-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
176 lines (139 loc) · 4.4 KB
/
script.js
File metadata and controls
176 lines (139 loc) · 4.4 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//Common JS
document
.querySelectorAll('.watch-control, .controls a, .iphone-btn')
.forEach((control) => {
control.addEventListener('click', (e) => {
e.preventDefault();
});
});
//End of Common JS
//Cube
let y = 20;
let x = 0;
let z = 0;
let bool = true;
let interval;
const cube = document.querySelector('.cube');
document.querySelector('.top-x-control').addEventListener('click', () => {
cube.style.transform = `rotateX(${(x += 20)}deg) rotateY(${y}deg) rotateZ(${z}deg)`;
});
document.querySelector('.bottom-x-control').addEventListener('click', () => {
cube.style.transform = `rotateX(${(x -= 20)}deg) rotateY(${y}deg) rotateZ(${z}deg)`;
});
document.querySelector('.left-y-control').addEventListener('click', () => {
cube.style.transform = `rotateX(${x}deg) rotateY(${(y -= 20)}deg) rotateZ(${z}deg)`;
});
document.querySelector('.right-y-control').addEventListener('click', () => {
cube.style.transform = `rotateX(${x}deg) rotateY(${(y += 20)}deg) rotateZ(${z}deg)`;
});
document.querySelector('.top-z-control').addEventListener('click', () => {
cube.style.transform = `rotateX(${x}deg) rotateY(${y}deg) rotateZ(${(z -= 20)}deg)`;
});
document.querySelector('.bottom-z-control').addEventListener('click', () => {
cube.style.transform = `rotateX(${x}deg) rotateY(${y}deg) rotateZ(${(z += 20)}deg)`;
});
const playPause = () => {
if (bool) {
interval = setInterval(() => {
cube.style.transform = `rotateX(${x}deg) rotateY(${y++}deg) rotateZ(${z}deg)`;
}, 100);
} else {
clearInterval(interval);
}
};
playPause();
document.querySelector('.controls').addEventListener('mouseover', () => {
bool = false;
playPause();
});
document.querySelector('.controls').addEventListener('mouseout', () => {
bool = true;
playPause();
});
//End of Cube
//Slideshow
const slideshowDivs = () => {
for (let i = 1; i <= 5; i++) {
const div = document.createElement('div');
div.style.backgroundImage = `url(images/slideshow/section-1-bg-${i}.jpg)`;
i === 1 && div.classList.add('change');
document.querySelector('.slideshow').appendChild(div);
}
};
slideshowDivs();
const divs = document.querySelectorAll('.slideshow div');
let a = 1;
const slideshow = () => {
setInterval(() => {
a++;
const div = document.querySelector('.slideshow .change');
div.classList.remove('change');
if (a < divs.length) {
div.nextElementSibling.classList.add('change');
} else {
divs[0].classList.add('change');
a = 1;
}
}, 20000);
};
slideshow();
//End of Slideshow
//Section-3
const section3Content = document.querySelector('.section-3-content');
window.addEventListener('scroll', () => {
if (
window.pageYOffset + window.innerHeight >=
section3Content.offsetTop + section3Content.offsetHeight / 2
) {
section3Content.classList.add('change');
}
});
//End of Section-3
//Section 4
const watchBands = document.querySelector('.watch-bands');
const watchCases = document.querySelector('.watch-cases');
const watchTopControl = document.querySelector('.watch-top-control');
const watchRightControl = document.querySelector('.watch-right-control');
const watchBottomControl = document.querySelector('.watch-bottom-control');
const watchLeftControl = document.querySelector('.watch-left-control');
let axisY = 0;
let axisX = 0;
const hideControl = () => {
if (axisY === -280) {
watchTopControl.classList.add('hideControl');
} else {
watchTopControl.classList.remove('hideControl');
}
if (axisY === 280) {
watchBottomControl.classList.add('hideControl');
} else {
watchBottomControl.classList.remove('hideControl');
}
if (axisX === 280) {
watchRightControl.classList.add('hideControl');
} else {
watchRightControl.classList.remove('hideControl');
}
if (axisX === -280) {
watchLeftControl.classList.add('hideControl');
} else {
watchLeftControl.classList.remove('hideControl');
}
};
watchTopControl.addEventListener('click', () => {
watchCases.style.marginTop = `${(axisY -= 70)}rem`;
hideControl();
});
watchBottomControl.addEventListener('click', () => {
watchCases.style.marginTop = `${(axisY += 70)}rem`;
hideControl();
});
watchRightControl.addEventListener('click', () => {
watchBands.style.marginRight = `${(axisX += 70)}rem`;
hideControl();
});
watchLeftControl.addEventListener('click', () => {
watchBands.style.marginRight = `${(axisX -= 70)}rem`;
hideControl();
});
//End of Section 4