-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
35 lines (29 loc) · 949 Bytes
/
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
//carousel function:
function carousel() {
var i;
var x = document.getElementsByClassName("slides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
slideIndex++;
if (slideIndex > x.length) {slideIndex = 1}
x[slideIndex-1].style.display = "block";
setTimeout(carousel, 2000); // Change image every 2 seconds
}
// Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
function stickyHeader() {
if (window.scrollY > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
// Get the header
var header = document.querySelector("header");
// Get the offset position of the navbar
var sticky = header.offsetTop;
// When the user scrolls the page, execute myFunction
window.onscroll = function() {stickyHeader()};
//Apply carousel:
var slideIndex = 0;
carousel();