Skip to content

Instantly share code, notes, and snippets.

@hunterirving
Created October 12, 2020 06:26
Show Gist options
  • Save hunterirving/ca4570876d51dc00794f92a266753aa7 to your computer and use it in GitHub Desktop.
Save hunterirving/ca4570876d51dc00794f92a266753aa7 to your computer and use it in GitHub Desktop.
glitchy/wiggly text in html using javascript
<script>
function glitch(caller) {
var x = caller.textContent
randIndex = Math.floor(Math.random() * x.length)
upperOrLower = Math.round(Math.random())
if(upperOrLower > 0.5)
{
caller.innerHTML = x.substring(0, randIndex) + x.charAt(randIndex).toLowerCase() + x.substring(randIndex+1, x.length)
}
else if(upperOrLower < 0.5)
{
caller.innerHTML = x.substring(0, randIndex) + x.charAt(randIndex).toUpperCase() + x.substring(randIndex+1, x.length)
}
}
window.onload = function callem() {
setInterval(function() {glitch(document.getElementById("<ELEMENT_NAME>"));}, <INTERVAL>);
setInterval(function() {glitch(document.getElementById("<ELEMENT_NAME>"));}, <INTERVAL>);
setInterval(function() {glitch(document.getElementById("<ELEMENT_NAME>"));}, <INTERVAL>);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment