-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (27 loc) · 1.36 KB
/
app.js
File metadata and controls
34 lines (27 loc) · 1.36 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
const translate = document.querySelectorAll(".translate");
const big_title = document.querySelector(".big-title");
const header = document.querySelector("header");
const shadow = document.querySelector(".shadow");
const content = document.querySelector(".content");
const section = document.querySelector("section");
const image_container = document.querySelector(".imgContainer");
const opacity = document.querySelectorAll(".opacity");
const border = document.querySelector(".border");
let header_height = header.offsetHeight;
let section_height = section.offsetHeight;
window.addEventListener('scroll', () => {
let scroll = window.pageYOffset;
let sectionY = section.getBoundingClientRect();
translate.forEach(element => {
let speed = element.dataset.speed;
element.style.transform = `translateY(${scroll * speed}px)`;
});
opacity.forEach(element => {
element.style.opacity = scroll / (sectionY.top + section_height);
})
big_title.style.opacity = - scroll / (header_height / 2) + 1;
shadow.style.height = `${scroll * 0.5 + 300}px`;
content.style.transform = `translateY(${scroll / (section_height + sectionY.top) * 50 - 50}px)`;
image_container.style.transform = `translateY(${scroll / (section_height + sectionY.top) * -50 + 50}px)`;
border.style.width = `${scroll / (sectionY.top + section_height) * 30}%`;
})