-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparkle.js
31 lines (28 loc) · 922 Bytes
/
sparkle.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
document.addEventListener("DOMContentLoaded", function () {
var body = document.getElementById('sparkle-background');
var template = document.querySelector('.template.sparkle');
var stars = 500;
var sparkle = 20;
var size = 'small';
var createStar = function () {
var star = template.cloneNode(true);
star.removeAttribute('id');
star.style.top = (Math.random() * 100) + '%';
star.style.left = (Math.random() * 100) + '%';
star.style.animationDelay = (Math.random() * sparkle) + 's';
star.style.WebkitAnimationDelay = (Math.random() * sparkle) + 's';
star.style.MozAnimationDelay = (Math.random() * sparkle) + 's';
star.classList.add(size);
body.appendChild(star);
};
for (var i = 0; i < stars; i++) {
if (i % 2 === 0) {
size = 'small';
} else if (i % 3 === 0) {
size = 'medium';
} else {
size = 'large';
}
createStar();
}
});