-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
182 lines (149 loc) · 4.35 KB
/
script.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
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
177
178
179
180
181
182
// Cube
const cube = document.querySelector(".cube");
let x = 0;
let y = 20;
let z = 0;
let boolean = true;
let interval = "";
const selectEle = (name, func) => {
const ele = document.querySelector(name);
ele.addEventListener("click", func);
return ele;
};
selectEle(".top-x-control", () => {
cube.style.transform = `rotateX(${(x += 20)}deg) rotateY(${y}deg) rotateZ(${z}deg)`;
});
selectEle(".bottom-x-control", () => {
cube.style.transform = `rotateX(${(x -= 20)}deg) rotateY(${y}deg) rotateZ(${z}deg)`;
});
selectEle(".left-y-control", () => {
cube.style.transform = `rotateY(${(y -= 20)}deg) rotateX(${x}deg) rotateZ(${z}deg)`;
});
selectEle(".right-y-control", () => {
cube.style.transform = `rotateY(${(y += 20)}deg) rotateX(${x}deg) rotateZ(${z}deg)`;
});
selectEle(".top-z-control", () => {
cube.style.transform = `rotateY(${y}deg) rotateX(${x}deg) rotateZ(${(z -= 20)}deg)`;
});
selectEle(".bottom-z-control", () => {
cube.style.transform = `rotateY(${y}deg) rotateX(${x}deg) rotateZ(${(z += 20)}deg)`;
});
const playPause = () => {
if (boolean) {
interval = setInterval(() => {
cube.style.transform = `rotateX(${x}deg) rotateY(${y++}deg) rotateZ(${z}deg)`;
}, 100);
} else {
clearInterval(interval);
}
};
playPause();
const controls = document.querySelector(".controls");
controls.addEventListener("mouseover", () => {
boolean = false;
playPause();
});
controls.addEventListener("mouseout", () => {
boolean = true;
playPause();
});
// End 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("active");
const slideshow = document.querySelector(".slideshow");
slideshow.appendChild(div);
}
};
slideshowDivs();
const divs = document.querySelectorAll(".slideshow div");
let a = 1;
const slideshow = () => {
setInterval(() => {
a++;
const div = document.querySelector(".slideshow .active");
div.classList.remove("active");
if (a < divs.length) {
div.nextElementSibling.classList.add("active");
} else {
divs[0].classList.add("active");
a = 1;
}
}, 10000);
};
slideshow();
// End slideshow
// Macbook section
const macbookSectionContent = document.querySelector(".content");
window.addEventListener("scroll", () => {
if (
window.pageYOffset + window.innerHeight >=
macbookSectionContent.offsetTop + macbookSectionContent.offsetHeight / 2
) {
macbookSectionContent.classList.add("active");
}
});
// end macbook section
// watches section
const allLinks = document.querySelectorAll(
".watch-control, .controls a, iphone-btn"
);
allLinks.forEach((link) => {
link.addEventListener("click", (e) => {
e.preventDefault();
});
});
const select = (name) => {
const ele = document.querySelector(name);
return ele;
};
const watchBands = select(".watch-bands");
const watchCases = select(".watch-cases");
const watchTopControl = select(".watch-top-control");
const watchRightControl = select(".watch-right-control");
const watchBottomControl = select(".watch-bottom-control");
const watchLeftControl = select(".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 watches section