-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
94 lines (77 loc) · 2.44 KB
/
app.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
const logo = document.querySelectorAll("#logo path");
console.log(logo);
battstatus = async () => {
stat = await window.navigator.getBattery();
console.log(stat);
};
battstatus();
for (i = 0; i < logo.length; i++) {
console.log(`Letter ${i} is ${logo[i].getTotalLength()}`);
}
setTimeout(function () {
window.location.href =
"file:///C:/Users/goels/Desktop/Text-Animation/hacktober.html";
}, 5000);
// Mode Switching - Dark Mode -Light Mode
function color_change(){
body = document.getElementById('body')
var currentClass = body.className;
body.className = currentClass == "light-mode" ? "dark-mode" : "light-mode";
}
// Changing Text of Mode Switch Button
function changeText(el, dText, nText) {
var content = "",
context = "";
// Change button text according to current text
function setText() {
return content === dText ? nText : dText;
}
/* Check to see if the browser accepts textContent */
if ("textContent" in document.body) {
context = "textContent";
content = el[context];
} else {
content = el.firstChild.nodeValue;
}
/* Set button text */
if (context === "textContent") {
el.textContent = setText();
} else {
el.firstChild.nodeValue = setText();
}
}
var defaultText, substituteText, btn;
defaultText = "LIGHT MODE";
substituteText = "DARK MODE";
btn = document.querySelector(".button");
// Listener for Mode Switch Button
btn.addEventListener(
"click",
function () {
changeText(this, defaultText, substituteText);
},
false
);
// Mouse Hover over Text Animation
(function () {
const link = document.querySelectorAll(".hover-this");
const cursor = document.querySelector(".cursor");
const animateit = function (e) {
const span = this.querySelector("span");
const { offsetX: x, offsetY: y } = e,
{ offsetWidth: width, offsetHeight: height } = this,
move = 25,
xMove = (x / width) * (move * 2) - move,
yMove = (y / height) * (move * 2) - move;
span.style.transform = `translate(${xMove}px, ${yMove}px)`;
if (e.type === "mouseleave") span.style.transform = "";
};
const editCursor = (e) => {
const { clientX: x, clientY: y } = e;
cursor.style.left = x + "px";
cursor.style.top = y + "px";
};
link.forEach((b) => b.addEventListener("mousemove", animateit));
link.forEach((b) => b.addEventListener("mouseleave", animateit));
window.addEventListener("mousemove", editCursor);
})();