-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
142 lines (109 loc) · 4.14 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var span = document.querySelector(".typewriter span");
var textArr = span.getAttribute("data-text").split(", ");
var maxTextIndex = textArr.length;
var sPerChar = 0.15;
var sBetweenWord = 1.5;
var textIndex = 0;
typing(textIndex, textArr[textIndex]);
function typing(textIndex, text) {
var charIndex = 0;
var maxCharIndex = text.length - 1;
var typeInterval = setInterval(function () {
span.innerHTML += text[charIndex];
if (charIndex == maxCharIndex) {
clearInterval(typeInterval);
setTimeout(function() { deleting(textIndex, text) }, sBetweenWord * 1000);
} else {
charIndex += 1;
}
}, sPerChar * 1000);
}
function deleting(textIndex, text) {
var minCharIndex = 0;
var charIndex = text.length - 1;
var typeInterval = setInterval(function () {
span.innerHTML = text.substr(0, charIndex);
if (charIndex == minCharIndex) {
clearInterval(typeInterval);
textIndex + 1 == maxTextIndex ? textIndex = 0 : textIndex += 1;
setTimeout(function() { typing(textIndex, textArr[textIndex]) }, sBetweenWord * 1000);
} else {
charIndex -= 1;
}
}, sPerChar * 1000);
}
const toggleButton = document.getElementsByClassName('toggle-button')[0]
const navbarLinks = document.getElementsByClassName('navbar-links')[0]
toggleButton.addEventListener('click', () => {
navbarLinks.classList.toggle('active')
})
const backToTopButton = document.querySelector("#back-to-top-btn");
window.addEventListener("scroll", scrollFunction);
function scrollFunction() {
if (window.pageYOffset > 300) { // Show backToTopButton
if(!backToTopButton.classList.contains("btnEntrance")) {
backToTopButton.classList.remove("btnExit");
backToTopButton.classList.add("btnEntrance");
backToTopButton.style.display = "block";
}
}
else { // Hide backToTopButton
if(backToTopButton.classList.contains("btnEntrance")) {
backToTopButton.classList.remove("btnEntrance");
backToTopButton.classList.add("btnExit");
setTimeout(function() {
backToTopButton.style.display = "none";
}, 250);
}
}
}
backToTopButton.addEventListener("click", smoothScrollBackToTop);
// function backToTop() {
// window.scrollTo(0, 0);
// }
function smoothScrollBackToTop() {
const targetPosition = 0;
const startPosition = window.pageYOffset;
const distance = targetPosition - startPosition;
const duration = 750;
let start = null;
window.requestAnimationFrame(step);
function step(timestamp) {
if (!start) start = timestamp;
const progress = timestamp - start;
window.scrollTo(0, easeInOutCubic(progress, startPosition, distance, duration));
if (progress < duration) window.requestAnimationFrame(step);
}
}
function easeInOutCubic(t, b, c, d) {
t /= d/2;
if (t < 1) return c/2*t*t*t + b;
t -= 2;
return c/2*(t*t*t + 2) + b;
};
/*<!---- this is part for trying --><!---- this is part for trying --><!---- this is part for checking phones -->*/
function openCity(evt, cityName) {
// Declare all variables
var i, tabcontent, tablinks;
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
// Show the current tab, and add an "active" class to the button that opened the tab
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
/*ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt*/
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
/* Set the width of the side navigation to 0 */
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}