-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
80 lines (66 loc) · 2.67 KB
/
Copy pathscript.js
File metadata and controls
80 lines (66 loc) · 2.67 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
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
//javascript for navigation bar effects on scroll
window.addEventListener("scroll", function(){
const header = document.querySelector("header");
header.classList.toggle('sticky', window.scrollY > 0);
});
//javascript for responsive navigation sidebar menu
const menuBtn = document.querySelector(".menu-btn");
const navigation = document.querySelector(".navigation");
const navigationItems = document.querySelectorAll(".navigation a")
menuBtn.addEventListener("click", () => {
menuBtn.classList.toggle("active");
navigation.classList.toggle("active");
});
navigationItems.forEach((navigationItem) => {
navigationItem.addEventListener("click", () => {
menuBtn.classList.remove("active");
navigation.classList.remove("active");
});
});
//javascript for scroll to top button
const scrollBtn = document.querySelector(".scrollToTop-btn");
window.addEventListener("scroll", function(){
scrollBtn.classList.toggle("active", window.scrollY > 500);
});
//javascript for scroll back to top on click scroll-to-top button
scrollBtn.addEventListener("click", () => {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
});
//javascript for reveal website elements on scroll
window.addEventListener("scroll", reveal);
function reveal(){
var reveals = document.querySelectorAll(".reveal");
for(var i = 0; i < reveals.length; i++){
var windowHeight = window.innerHeight;
var revealTop = reveals[i].getBoundingClientRect().top;
var revealPoint = 50;
if(revealTop < windowHeight - revealPoint){
reveals[i].classList.add("active");
}
}
}
//popup code
const popupScreen = document.querySelector(".popup-screen");
const popupBox = document.querySelector(".popup-box");
const closeBtn = document.querySelector(".close-btn");
window.addEventListener("load", () => {
setTimeout(() => {
popupScreen.classList.add("active");
}, 2000); //Popup the screen in 02 seconds after the page is loaded.
});
closeBtn.addEventListener("click", () => {
popupScreen.classList.remove("active"); //Close the popup screen on click the close button.
//Create a cookie for a day (to expire within a day) on click the close button.
document.cookie = "WebsiteName=testWebsite; max-age=" + 24 * 60 * 60; //1 day = 24 hours = 24*60*60
});
//Use the created cookie to hide or show the popup screen.
const WebsiteCookie = document.cookie.indexOf("WebsiteName=");
if(WebsiteCookie != -1){
popupScreen.style.display = "none"; //Hide the popup screen if the cookie is not expired.
}
else{
popupScreen.style.display = "flex"; //Show the popup screen if the cookie is expired.
}
//popup code close
//