I am trying to make it so that when i hover my div it does a "hacker" effect on the text inside and transitions it from just random letters into an actual word, then once i stop hovering, it does the same effect. either back to the "random" pre-written letters, or if possible actually random letters
This is the Code i currently have, the first 2 lines are to check if the element is on the current webpage as its apart of a multi web-page code.
let pxScreen1 = document.getElementsByClassName("screen1");
if ( pxScreen1 !== null ) {
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let interval = null;
const screen = document.querySelector(".screen1"),
name = document.querySelector(".name1");
screen.onmouseenter = event => {
let iteration = 0;
clearInterval(interval);
interval = setInterval(() => {
name.innerText = name.innerText
.split("")
.map((letter, index) => {
if(index < iteration) {
return name.dataset.value[index];
}
return letters[Math.floor(Math.random() * 26)]
})
.join("");
if(iteration >= name.dataset.value.length){
clearInterval(interval);
}
iteration += 1 / 3;
}, 40);
}
}