-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
100 lines (74 loc) · 2.72 KB
/
app.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
const showOnPx = 10;
const backToTopButton = document.querySelector(".back-to-top");
const pageProgressBar = document.querySelector(".progress-bar1");
const parallelogram = document.getElementsByClassName("paralleogram");
const schedule = document.getElementById("scroll");
window.addEventListener("scroll" , ()=>{
let last_height = document.getElementById("last").getBoundingClientRect().top;
let scroll1 = window.scrollY + 200;
let first_height = document.getElementById("first").getBoundingClientRect().top - 250;
console.log(`scroll = ${scroll1} and height = ${first_height}`);
let box_top = schedule.getBoundingClientRect().top;
// console.log(scroll1);
if(first_height < 0 && last_height > 0 ){
let number_of_boxes = scroll1/(( last_height - first_height)/6) -1
console.log(number_of_boxes);
for(let i = 0 ; i < 6 ; i++){
if(i < number_of_boxes-1){
parallelogram[i].style.backgroundColor = "#0C62E4";
}
else if(i === number_of_boxes){
parallelogram[i].style.backgroundColor = "#0C62E4" ;
parallelogram[i].style.opacity = `${scroll%((first_height - last_height)/6)}%` ;
}
else{
parallelogram[i].style.backgroundColor = "white";
}
}
}
else if(first_height > 0){
for(var i = 0 ;i < 6 ;i ++){
parallelogram[i].style.backgroundColor = "white" ;
}
}
})
document.addEventListener("DOMContentLoaded", function () {
const menuToggle = document.querySelector(".menu-toggle");
const mobileNav = document.querySelector(".mobile-navbar");
menuToggle.addEventListener("click", function () {
mobileNav.classList.toggle("open");
});
document.addEventListener("click", function (event) {
if (mobileNav.contains(event.target) || !menuToggle.contains(event.target)) {
mobileNav.classList.remove("open");
}
});
});
const scrollContainer = () => {
return document.documentElement || document.body;
};
const goToTop = () => {
document.body.scrollIntoView({
behavior: "smooth"
});
};
document.addEventListener("scroll", () => {
// console.log("Scroll Height: ", scrollContainer().scrollHeight);
// console.log("Client Height: ", scrollContainer().clientHeight);
const scrolledPercentage =
(scrollContainer().scrollTop /
(scrollContainer().scrollHeight - scrollContainer().clientHeight)) *
100;
pageProgressBar.style.width = `${scrolledPercentage}%`;
if (scrollContainer().scrollTop > showOnPx) {
backToTopButton.classList.remove("hidden");
} else {
backToTopButton.classList.add("hidden");
}
});
backToTopButton.addEventListener("click", goToTop);
// console.log("hello");
let card1 =()=>{
window.alert("hello");
}
// let pos = window.addEventListener("load" , card1)