-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntery.html
68 lines (61 loc) · 2.27 KB
/
Entery.html
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script>
;(function($){
jQuery.fn.entry = function(options){
options = $.extend({
elem: jQuery(this),
e: undefined,
invert: false,
namespace: 'entry',
sides: [ 'up', 'right', 'down', 'left' ]
}, options);
var mouseCrossedElementsBorder = function(e, elem){
var w = elem.width(),
h = elem.height(),
pointX, pointY, offsetX, offsetY, modeLR, modeTB, direction,
eoffsetX = (e.offsetX || e.clientX - $(e.target).offset().left + window.pageXOffset ),
eoffsetY = (e.offsetY || e.clientY - $(e.target).offset().top + window.pageYOffset );
// Determine border point horizontaly
if( eoffsetX < w/2){
pointX = !options.invert ? options.sides[3] : options.sides[1];
offsetX = eoffsetX;
modeLR = 0;
}else if( eoffsetX > w/2 && (eoffsetX - w <= w/2) ){
pointX = !options.invert ? options.sides[1] : options.sides[3];
offsetX = (eoffsetY < h/2) ? w - eoffsetX : eoffsetX - w;
modeLR = 1;
}
// Determine border point vertically
if( eoffsetY < h/2){
pointY = !options.invert ? options.sides[0] : options.sides[2];
offsetY = eoffsetY;
modeTB = 0;
}else if( eoffsetY > h/2 && (eoffsetY - h <= h/2) ){
pointY = !options.invert ? options.sides[2] : options.sides[0];
offsetY = (eoffsetX < w/2) ? h - eoffsetY : eoffsetY - h;
modeTB = 1;
}
// Determine what side was closer: horizontaly or vertically
if(modeLR == 1 && modeTB == 1){
direction = (offsetX > offsetY) ? pointX : pointY;
}else if( (modeLR == 0 && modeTB == 0) || (modeLR == 1 && modeTB == 0) || (modeLR == 0 && modeTB == 1) ){
direction = (offsetX < offsetY) ? pointX : pointY;
}
return direction;
};
if( typeof(options.e) == 'undefined')
console.log('Entry plugin requires Event Object ')
else
return mouseCrossedElementsBorder(options.e, options.elem);
};
})(jQuery);
</script>
</body>
</html>