generated from nisarhassan12/portfolio-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
120 lines (103 loc) · 3.24 KB
/
index.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* -----------------------------------------
Have focus outline only for keyboard users
---------------------------------------- */
const handleFirstTab = (e) => {
if(e.key === 'Tab') {
document.body.classList.add('user-is-tabbing')
window.removeEventListener('keydown', handleFirstTab)
window.addEventListener('mousedown', handleMouseDownOnce)
}
}
const handleMouseDownOnce = () => {
document.body.classList.remove('user-is-tabbing')
window.removeEventListener('mousedown', handleMouseDownOnce)
window.addEventListener('keydown', handleFirstTab)
}
window.addEventListener('keydown', handleFirstTab)
const backToTopButton = document.querySelector(".back-to-top");
let isBackToTopRendered = false;
let alterStyles = (isBackToTopRendered) => {
backToTopButton.style.visibility = isBackToTopRendered ? "visible" : "hidden";
backToTopButton.style.opacity = isBackToTopRendered ? 1 : 0;
backToTopButton.style.transform = isBackToTopRendered
? "scale(1)"
: "scale(0)";
};
window.addEventListener("scroll", () => {
if (window.scrollY > 700) {
isBackToTopRendered = true;
alterStyles(isBackToTopRendered);
} else {
isBackToTopRendered = false;
alterStyles(isBackToTopRendered);
}
});
let slideIndex = 1;
let slide2Index = 1;
showSlides(slideIndex);
showSlides2(slide2Index);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function plusSlides2(n) {
showSlides2(slide2Index += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function currentSlide2(n) {
showSlides2(slide2Index = n);
}
function showSlides2(n) {
let i;
let slides = document.getElementsByClassName("mySlides2");
let dots = document.getElementsByClassName("dot2");
if (n > slides.length) {slide2Index = 1}
if (n < 1) {slide2Index = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slide2Index-1].style.display = "block";
dots[slide2Index-1].className += " active";
}
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
let dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
// Get the video
var video = document.getElementById("myVideo");
// Get the button
var btn = document.getElementById("pauseButton");
// Pause and play the video, and change the button text
function pauseVideo() {
if (video.paused) {
video.play();
btn.innerHTML = "Pause";
} else {
video.pause();
btn.innerHTML = "Play";
}
}
/* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */
function toggleResponsiveDesignTopNav() {
var x = document.getElementById("myTopnav");
if (x.className === "nav") {
x.className += " responsive";
} else {
x.className = "nav";
}
}