-
-
Notifications
You must be signed in to change notification settings - Fork 237
/
mouseidle.js
50 lines (42 loc) · 923 Bytes
/
mouseidle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var $ = require('dombo')
module.exports = function (elem, timeout, className) {
var max = (timeout / 250) | 0
var overMovie = false
var hiding = false
var moving = 0
var tick = 0
var mousedown = false
var update = function () {
if (hiding) {
$('body').removeClass(className)
hiding = false
}
}
$(elem).on('mouseover', function () {
overMovie = true
update()
})
$(elem).on('mouseout', function () {
overMovie = false
})
$(elem).on('mousedown', function (e) {
mousedown = true
moving = tick
update()
})
$(elem).on('mouseup', function (e) {
mousedown = false
moving = tick
})
$(window).on('mousemove', function (e) {
moving = tick
update()
})
setInterval(function () {
tick++
if (!overMovie) return
if (tick - moving < max || mousedown) return
hiding = true
$('body').addClass(className)
}, 250)
}