1
0
hugo/static/js/nyan.js

30 lines
782 B
JavaScript
Raw Permalink Normal View History

2024-04-23 13:21:26 +00:00
console.log('Nyan!')
function cycleFrames (_nyanCat, _currentFrame) {
_nyanCat.classList = []
_nyanCat.classList.add(`frame${_currentFrame}`)
}
function replicateSparks (_sparksRow) {
const numberOfRowsToCoverEntireScreen = Math.ceil(document.body.offsetHeight / _sparksRow.offsetHeight)
const newSparksRows = document.createElement('div')
for (let a = 0; a < numberOfRowsToCoverEntireScreen-1; a++) {
newSparksRows.append(_sparksRow.cloneNode(true))
}
document.body.prepend(newSparksRows)
}
(function () {
let nyanCat = document.getElementById('nyan-cat')
let currentFrame = 1
replicateSparks(document.getElementsByClassName('sparks-combo')[0])
setInterval(function () {
currentFrame = (currentFrame % 6) + 1
cycleFrames(nyanCat, currentFrame)
}, 70)
})()