Skip to content

Instantly share code, notes, and snippets.

@PustakP
Created March 31, 2023 07:44
Show Gist options
  • Save PustakP/3a1d0c07e6b5bec3a4805cc3a4fb8219 to your computer and use it in GitHub Desktop.
Save PustakP/3a1d0c07e6b5bec3a4805cc3a4fb8219 to your computer and use it in GitHub Desktop.
Hacked Text Effect
<h1 data-value="PUSTAK PATHAK">PUSTAK PATHAK</h1>
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let interval = null;
document.querySelector("h1").onmouseover = event => {
let iteration = 0;
clearInterval(interval);
interval = setInterval(() => {
event.target.innerText = event.target.innerText
.split("")
.map((letter, index) => {
if(index < iteration) {
return event.target.dataset.value[index];
}
return letters[Math.floor(Math.random() * 26)]
})
.join("");
if(iteration >= event.target.dataset.value.length){
clearInterval(interval);
}
iteration += 1 / 3;
}, 50);
}
<script src="https://codepen.io/Hyperplexed/pen/xxYJYjM/54407644e24173ad6019b766443bf2a6.js"></script>
body {
display: grid;
place-items: center;
height: 100vh;
background-color: black;
margin: 0rem;
overflow: hidden;
}
h1 {
font-family: 'Space Mono', monospace;
font-size: clamp(3rem, 10vw, 10rem);
color: white;
padding: 0rem clamp(1rem, 2vw, 3rem);
border-radius: clamp(0.4rem, 0.75vw, 1rem);
}
h1:hover {
background-color: white;
color: black;
}
a:link { text-decoration: none; }
a:visited { text-decoration: none; }
a:hover { text-decoration: none; }
a:active { text-decoration: none; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment