tylerperkins.xyz/themes/clortox/static/js/script.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-07-15 22:44:31 +00:00
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
window.onload = function() {
document.querySelectorAll(".scramble").forEach(item => {
item.addEventListener("mouseover", scramble);
});
2023-07-18 03:17:11 +00:00
window.addEventListener('scroll', function() {
const parallax = document.querySelector('.parallax')
let scrollPosition = window.pageYOffset;
parallax.style.transform = 'translateY(' + scrollPosition * .5 + 'px)';
})
2023-07-15 22:44:31 +00:00
}
2023-07-16 00:59:44 +00:00
function scramble(event){
scrambleLetters(event.target);
}
function scrambleLetters(element) {
2023-07-15 22:44:31 +00:00
let iterations = 0;
2023-07-16 00:59:44 +00:00
const originalValue = element.dataset.value;
2023-07-15 22:44:31 +00:00
let interval = setInterval(() => {
2023-07-16 00:59:44 +00:00
element.innerText = element.innerText.split("")
2023-07-15 22:44:31 +00:00
.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);
2023-07-16 00:59:44 +00:00
element.innerText = originalValue;
2023-07-15 22:44:31 +00:00
}
}, 30);
}
2023-07-16 00:59:44 +00:00