Created
October 12, 2020 06:26
-
-
Save hunterirving/ca4570876d51dc00794f92a266753aa7 to your computer and use it in GitHub Desktop.
glitchy/wiggly text in html using javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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