-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallaxtext.js
71 lines (55 loc) · 1.52 KB
/
parallaxtext.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
$(function () {
let l2PosX = $("#layer-2").offset().left,
l2PosY = $("#layer-2").offset().top;
let l3PosX = $("#layer-3").offset().left,
l3PosY = $("#layer-3").offset().top;
let l4PosX = $("#layer-4").offset().left,
l4PosY = $("#layer-4").offset().top;
// l2PosX -= l2PosX * 0.015
// l2PosY -= l2PosY * 0.015
// l3PosX -= l3PosX * 0.03
// l3PosY -= l3PosY * 0.03
// l4PosX -= l4PosX * 0.045
// l4PosY -= l4PosY * 0.045
$("#layer-2").css({
"left": l2PosX,
"top": l2PosY
})
$("#layer-3").css({
"left": l3PosX,
"top": l3PosY
})
$("#layer-4").css({
"left": l4PosX,
"top": l4PosY
})
let init = false;
let startX = 0;
let startY = 0;
let posX = 0;
let posY = 0;
$(document).on("mousemove", function (event) {
if (init) {
posX -= startX;
posY -= startY;
$("#layer-2").css({
"left": l2PosX - (posX * .016),
"top": l2PosY - (posY * .016)
})
$("#layer-3").css({
"left": l3PosX - (posX * .03),
"top": l3PosY - (posY * .03)
})
$("#layer-4").css({
"left": l4PosX - (posX * .045),
"top": l4PosY - (posY * .045)
})
} else {
startX = event.pageX;
startY = event.pageY;
}
posX = event.pageX;
posY = event.pageY;
init = true;
})
})