-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
90 lines (71 loc) · 2.8 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
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
function zoomImage(imageUrl) {
// Open the image in a new window
var newWindow = window.open("", "_blank");
newWindow.document.write(
'<html><head><title>Lucifer</title></head><body style="margin:0;display:flex;justify-content:center;align-items:center;height:100vh;background-color:#000;"><img src="' +
imageUrl +
'" style="max-width:100%;max-height:100%;" alt="Zoomed Image"></body></html>'
);
newWindow.document.close();
window.onload = function () {
alert("If you get any error \nkindly view in desktop mode");
};
}
document.addEventListener("DOMContentLoaded", function () {
document
.getElementById("commentForm")
.addEventListener("submit", function (event) {
event.preventDefault();
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const message = document.getElementById("message").value;
const mailtoLink = `mailto:[email protected]?subject=Comment from ${name}&body=Name: ${name}%0AEmail: ${email}%0AMessage: ${message}`;
window.location.href = mailtoLink;
alert("Your message has been sent!");
document.getElementById("commentForm").reset();
});
});
const toggleButton = document.getElementById("mode-toggle");
function setTheme(theme) {
document.documentElement.setAttribute("data-theme", theme);
localStorage.setItem("theme", theme);
toggleButton.textContent =
theme === "dark" ? "Switch to Light Mode" : "Switch to Dark Mode";
}
// Check for saved user preference, if any, on load
const savedTheme = localStorage.getItem("theme") || "light";
setTheme(savedTheme);
toggleButton.addEventListener("click", () => {
const currentTheme = document.documentElement.getAttribute("data-theme");
const newTheme = currentTheme === "dark" ? "light" : "dark";
setTheme(newTheme);
});
// scroll
document.addEventListener('DOMContentLoaded', function () {
const scrollElements = document.querySelectorAll('.scroll-animation');
const elementInView = (el, dividend = 1) => {
const elementTop = el.getBoundingClientRect().top;
return (
elementTop <=
(window.innerHeight || document.documentElement.clientHeight) / dividend
);
};
const displayScrollElement = (element) => {
element.classList.add('visible');
};
const hideScrollElement = (element) => {
element.classList.remove('visible');
};
const handleScrollAnimation = () => {
scrollElements.forEach((el) => {
if (elementInView(el, 1.25)) {
displayScrollElement(el);
} else {
hideScrollElement(el);
}
});
};
window.addEventListener('scroll', () => {
handleScrollAnimation();
});
});