-
Notifications
You must be signed in to change notification settings - Fork 1
/
deadsea.js
41 lines (34 loc) · 1.06 KB
/
deadsea.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
(function(context) {
var deadsea = {};
function isFamily(parent, child) {
if (parent === child) return true;
var node = child.parentNode;
while (node !== null) {
if (node === parent) {
return true;
} else {
node = node.parentNode;
}
}
return false;
}
deadsea.blockScrollInto = function(el) {
var locked = true;
// This is not compatible with IE.
if (!window.addEventListener) return this;
function handleMouseWheel(e) {
if (!isFamily(el, e.target)) {
locked = true;
} else if (locked) {
e.stopPropagation();
}
}
window.addEventListener('mousewheel', handleMouseWheel, true);
window.addEventListener('DOMMouseScroll', handleMouseWheel, true);
el.addEventListener('mousemove', function mousemove(e) {
locked = false;
}, false);
return this;
};
this.deadsea = deadsea;
})(this);