forked from hound77/jwoc-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake.js
81 lines (78 loc) · 1.83 KB
/
snake.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(function ( $ ) {
$.fn.snakeify = function( options ) {
var settings = $.extend({
inaccuracy: 30,
speed: 200
}, options );
this.find('.overlay').css({top: -9999999});
this.mouseenter(function(e){
const container = $(this);
const overlay = container.find('.overlay');
const parentOffset = container.offset();
const relX = e.pageX - parentOffset.left;
const relY = e.pageY - parentOffset.top;
overlay.css({
top: 0,
left: 0,
width: container.width(),
height: container.height()
});
if(relX > container.width()-settings.inaccuracy){
overlay.css({
top: 0,
left: container.width(),
});
}else if(relX < settings.inaccuracy){
overlay.css({
top: 0,
left: -container.width(),
});
}else if(relY > container.width()-settings.inaccuracy){
overlay.css({
top: container.width(),
left: 0,
});
}else if(relY < settings.inaccuracy){
overlay.css({
top: -container.width(),
left: 0,
});
}
overlay.animate({
top: 0,
left: 0
},settings.speed);
});
this.mouseleave(function(e){
const container = $(this);
const overlay = container.find('.overlay');
const parentOffset = container.offset();
const relX = e.pageX - parentOffset.left;
const relY = e.pageY - parentOffset.top;
if(relX <= 0){
overlay.animate({
top: 0,
left: -container.width()
},settings.speed);
}
if(relX >= container.width()) {
overlay.animate({
top: 0,
left: container.width()
},settings.speed);
}
if(relY <= 0){
overlay.animate({
left: 0,
top: -container.height()
},settings.speed);
}
if(relY >= container.height()){
overlay.animate({
left: 0,
top: container.height()
},settings.speed);
}
});
};
}( jQuery ));