1
0
hugo/static/js/nyan.js
2024-04-23 22:21:26 +09:00

30 lines
782 B
JavaScript

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)
})()