-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.js
62 lines (56 loc) · 1.79 KB
/
main.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
const load = document.querySelector(".load");
const car = document.querySelector("#car");
const city = document.querySelector(".city");
const plane = document.querySelector(".plane");
const wrapper = document.querySelector(".wrapper");
const button = document.querySelector("#button");
const audio = new Audio('./assets/walking-crowd-at-subway-station.wav');
const loadTime = setTimeout(()=>{
load.style.visibility = "hidden";
audio.play();
audio.loop = true;
}, 3000);
let prevData = 0;
window.addEventListener('scroll', function() {
let scrollpx = window.scrollY;
let totalH = $(document).height();
let windowH = $(window).height();
let totalV = $(document).width();
let windowV = $(window).width();
let value;
totalV = totalV - 60;
value = scrollpx * totalV;
value = value / (totalH - windowH);
if(prevData > value) {
car.style.transform = "scaleX(1.5) rotateY(0deg)";
} else {
car.style.transform = "scaleX(1.5) rotateY(180deg)";
}
prevData = value;
car.style.left = value + 'px';
totalH = $(document).height();
windowH = $(window).height();
totalV = $(document).width();
windowV = $(window).width();
if (windowV <= 900) {
city.style.position = "fixed";
city.style.height = "calc(35%)";
car.style.position = "fixed";
car.style.top = "calc(35% - 30px)";
plane.style.position = "fixed";
} else {
if (scrollpx > 120) {
city.style.position = "fixed";
city.style.height = "calc(50% - 100px)";
car.style.position = "fixed";
car.style.top = "calc(50% - 130px)";
plane.style.position = "fixed";
} else {
city.style.position = "absolute";
city.style.height = "50%";
car.style.position = "absolute";
car.style.top = "calc(50% - 30px)";
plane.style.position = "absolute";
}
}
})