-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
65 lines (53 loc) · 1.66 KB
/
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
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
function reveal() {
var reveals = document.querySelectorAll(".reveal");
for (var i = 0; i < reveals.length; i++) {
var windowHeight = window.innerHeight;
var elementTop = reveals[i].getBoundingClientRect().top;
var elementVisible = 150;
if (elementTop < windowHeight - elementVisible) {
reveals[i].classList.add("active");
} else {
reveals[i].classList.remove("active");
}
}
}
window.addEventListener("scroll", reveal);
/* arrow onclick scroll down */
document.addEventListener("DOMContentLoaded", function () {
const arrow = document.querySelector(".arrow");
arrow.addEventListener("click", () => {
const scrollDistance = window.innerHeight;
window.scrollBy(0, scrollDistance);
});
});
// bottom to top button script
$(document).ready(function () {
var btn = $("#button");
$(window).scroll(function () {
if ($(window).scrollTop() > 300) {
btn.addClass("show");
} else {
btn.removeClass("show");
}
});
btn.on("click", function (e) {
e.preventDefault();
window.scrollTo(0, 0);
});
});
// links for directing to specific content to tag
document.addEventListener("DOMContentLoaded", function() {
const navItems = document.querySelectorAll(".__container [data-section]");
navItems.forEach(function(item) {
item.addEventListener("click", function() {
const targetId = this.getAttribute("data-section");
const targetSection = document.getElementById(targetId);
if (targetSection) {
window.scrollTo({
top: targetSection.offsetTop,
behavior: "smooth"
});
}
});
});
});