-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
96 lines (83 loc) · 2.47 KB
/
script2.js
File metadata and controls
96 lines (83 loc) · 2.47 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class HoverButton {
constructor(el) {
this.el = el;
this.hover = false;
this.calculatePosition();
this.attachEventsListener();
}
attachEventsListener() {
window.addEventListener('mousemove', e => this.onMouseMove(e));
window.addEventListener('resize', e => this.calculatePosition(e));
}
calculatePosition() {
TweenMax.set(this.el, {
x: 0,
y: 0,
scale: 1
});
const box = this.el.getBoundingClientRect();
this.x = box.left + box.width * 0.5;
this.y = box.top + box.height * 0.5;
this.width = box.width;
this.height = box.height;
}
onMouseMove(e) {
let hover = false;
let hoverArea = this.hover ? 0.7 : 0.5;
let x = e.clientX - this.x;
let y = e.clientY - this.y;
let distance = Math.sqrt(x * x + y * y);
if (distance < this.width * hoverArea) {
hover = true;
if (!this.hover) {
this.hover = true;
}
this.onHover(e.clientX, e.clientY);
}
if (!hover && this.hover) {
this.onLeave();
this.hover = false;
}
}
onHover(x, y) {
TweenMax.to(this.el, 0.4, {
x: (x - this.x) * 0.4,
y: (y - this.y) * 0.4,
scale: 1.15,
ease: Power2.easeOut
});
this.el.style.zIndex = 10;
}
onLeave() {
TweenMax.to(this.el, 0.7, {
x: 0,
y: 0,
scale: 1,
ease: Elastic.easeOut.config(1.2, 0.4)
});
this.el.style.zIndex = 1;
}
}
var posX = posY = mouseX = mouseY = 0;
jQuery(window).load(function(e) {
jQuery('body').trigger('mousemove');
const btn1 = document.querySelector('.menu-icon');
new HoverButton(btn1);
});
jQuery(function() {
var prefix = function() {
var a = window.getComputedStyle(document.documentElement, ""),
b = (Array.prototype.slice.call(a).join("").match(/-(moz|webkit|ms)-/) || "" === a.OLink && ["", "o"])[1];
return "WebKit|Moz|MS|O".match(new RegExp("(" + b + ")", "i"))[1], "-" + b + "-"
}();
jQuery(document).mousemove(function(e) {
mouseX = e.pageX + 15;
mouseY = e.pageY - jQuery(window).scrollTop() + 15;
jQuery('.theBall-outer').attr('style', prefix + 'transform:translate(' + mouseX + 'px,' + mouseY + 'px)');
});
jQuery(document).on('mouseenter', 'a', '.menu-icon', function() {
jQuery('.theBall').addClass('zooming');
}).on('mouseleave', 'a', '.menu-icon', function() {
jQuery(".theBall").removeClass("zooming")
});
});