-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
99 lines (83 loc) · 3.09 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
// Add active class to the current control button in navbar(highlight it)
var navContainer = document.getElementById("nav-ul-filters");
var navBtns = navContainer.getElementsByClassName("nav-link");
for (var t = 0; t < navBtns.length; t++) {
navBtns[t].addEventListener("click", function() {
var navcurrent = document.getElementsByClassName("nav-active");
navcurrent[0].className = navcurrent[0].className.replace(" nav-active", "");
this.className += " nav-active";
});
}
// get the elements you want to animate
const jumbotron = document.querySelector('.jumbotron');
const text = document.querySelector('.float-txt');
const nav = document.querySelector('.n-scroll');
// jumbotron.style.transform = '50px';
// listen to the scroll event
window.addEventListener('scroll', function () {
// get the scroll position
const scrollPosition = window.pageYOffset;
// update the elements based on the scroll position
jumbotron.style.transform = `translateY(${scrollPosition * 0.5}px)`;
text.style.transform = `translateY(${scrollPosition * 0.3}px)`;
if (scrollPosition >= 900 ){
jumbotron.style.transform = `translateY(0px)`;
text.style.transform = `translateY(0px)`;
}
// console.log(scrollPosition);
if (scrollPosition >= 200 ) {
nav.classList.add("bg-white");
nav.classList.add("trans-nav")
nav.classList.remove("bg-transparent");
nav.style.transform = `translateY(0px)`;
}
else {
nav.classList.add("bg-transparent");
nav.classList.remove("bg-white");
// nav.style.transform = `translateY(${scrollPosition * -0.5}px)`;
}
});
// window.addEventListener('scroll', function () {
// console.log("object");
// });
filterSelection("all");
function filterSelection(c) {
var x, i;
x = document.getElementsByClassName("filterDiv");
if (c == "all") c = "";
for (i = 0; i < x.length; i++) {
w3RemoveClass(x[i], "show");
if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show");
}
}
function w3AddClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) == -1) {
element.className += " " + arr2[i];
}
}
}
function w3RemoveClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while (arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}
// Add active class to the current control button in recent work section (highlight it)
var btnContainer = document.getElementById("ul-filters");
var btns = btnContainer.getElementsByClassName("nav-link");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function() {
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
}