mirror of
https://github.com/Clortox/tylerperkins.xyz.git
synced 2026-03-07 10:37:58 +00:00
Add base index page
This commit is contained in:
29
themes/clortox/static/js/scramble.js
Normal file
29
themes/clortox/static/js/scramble.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
window.onload = function() {
|
||||
document.querySelectorAll(".scramble").forEach(item => {
|
||||
item.addEventListener("mouseover", scramble);
|
||||
});
|
||||
}
|
||||
|
||||
function scramble(event) {
|
||||
let iterations = 0;
|
||||
const originalValue = event.target.dataset.value;
|
||||
|
||||
let interval = setInterval(() => {
|
||||
event.target.innerText = event.target.innerText.split("")
|
||||
.map((letter, index) => {
|
||||
if(index < iterations){
|
||||
return originalValue[index];
|
||||
}
|
||||
return letters[Math.floor(Math.random() * letters.length)];
|
||||
}).join("")
|
||||
|
||||
iterations += 1 / 3;
|
||||
|
||||
if(iterations > originalValue.length){
|
||||
clearInterval(interval);
|
||||
event.target.innerText = originalValue;
|
||||
}
|
||||
}, 30);
|
||||
}
|
||||
Reference in New Issue
Block a user