-
Notifications
You must be signed in to change notification settings - Fork 6
/
script.js
39 lines (27 loc) · 1020 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
36
37
38
39
// modal opens when we click on image
const galleryImages = document.querySelectorAll('.gallery__image');
const modal = document.getElementById('modal');
const modalImage = document.querySelector('.modal__image');
const modalClose = document.querySelector('.modal__close');
galleryImages.forEach((image) => {
image.addEventListener('click', () => {
modal.style.display = 'flex';
modalImage.src = image.src;
});
});
modalClose.addEventListener('click', () => {
modal.style.display = 'none';
});
window.onscroll = function() {myFunction()};
// Get the navbar
var navbar = document.getElementById("navbar");
// Get the offset position of the navbar
var sticky = navbar.offsetTop;
// Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}