forked from Sumandeep-Kaur/Portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagic-script.js
More file actions
49 lines (36 loc) · 1.24 KB
/
Copy pathmagic-script.js
File metadata and controls
49 lines (36 loc) · 1.24 KB
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
let index = 0,
interval = 1000;
const rand = (min, max) =>
Math.floor(Math.random() * (max - min + 1)) + min;
const animate = star => {
star.style.setProperty("--star-left", `${rand(-10, 100)}%`);
star.style.setProperty("--star-top", `${rand(-40, 80)}%`);
star.style.animation = "none";
star.offsetHeight;
star.style.animation = "";
}
for(const star of document.getElementsByClassName("magic-star")) {
setTimeout(() => {
animate(star);
setInterval(() => animate(star), 1000);
}, index++ * (interval / 3))
}
/* -- ↓↓↓ If you want the sparkle effect to only occur on hover, replace lines 16 and on with this code ↓↓↓ -- */
// let timeouts = [],
// intervals = [];
// const magic = document.querySelector(".magic");
// magic.onmouseenter = () => {
// let index = 1;
// for(const star of document.getElementsByClassName("magic-star")) {
// timeouts.push(setTimeout(() => {
// animate(star);
// intervals.push(setInterval(() => animate(star), 1000));
// }, index++ * 300));
// };
// }
// magic.onmouseleave = onMouseLeave = () => {
// for(const t of timeouts) clearTimeout(t);
// for(const i of intervals) clearInterval(i);
// timeouts = [];
// intervals = [];
// }