-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (34 loc) · 1.33 KB
/
app.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
console.log("Hello World");
$(function() {
$(document).mousemove(function(e) {
moveDiv(e, 'parallax', 50, 50, 40);
moveDiv(e, 'much-events', 30, 20, 30);
moveDiv(e, 'many-js', 20, 80, 20);
moveDiv(e, 'wow', 60, 70, 10);
backgroundMove(e)
});
});
// Move a div around with mouse input
function moveDiv(e, id, left, bottom, sensitivity) {
pointerDeltaX = e.pageX - window.innerWidth/2;
pointerDeltaY = e.pageY - window.innerHeight/2;
elDeltaX = pointerDeltaX * sensitivity / (window.innerWidth/2);
elDeltaY = -1 * pointerDeltaY * sensitivity / (window.innerHeight/2);
elPosX = left + elDeltaX;
elPosY = bottom + elDeltaY;
console.log(elPosX + " " + elPosY);
document.getElementById(id).style.left = elPosX + "%";
document.getElementById(id).style.bottom = elPosY + "%";
}
// Move the positioning of the body's background with mouse input
function backgroundMove(e) {
console.log(e.pageX + " " + e.pageY);
sensitivity = 5;
pointerDeltaX = e.pageX - window.innerWidth/2;
pointerDeltaY = e.pageY - window.innerHeight/2;
imgDeltaX = -1 * pointerDeltaX * sensitivity / (window.innerWidth/2);
imgDeltaY = pointerDeltaY * sensitivity / (window.innerHeight/2);
imgBgPosX = -50 + imgDeltaX;
imgBgPosY = -50 + imgDeltaY;
document.body.style.backgroundPosition = imgBgPosX + "px " + imgBgPosY + "px";
}