Created
October 27, 2022 11:34
-
-
Save 0x48piraj/4cd7f8a1ae44cc70fbe89f87040a1ffe to your computer and use it in GitHub Desktop.
A small function for creating beautiful ASCII based animations on your website's title.
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
/* | |
usage: ASCIIAnimation(param1, param2, param3) | |
param1 - array of animation 'frames' (strings) | |
param2 - speed of animation in ms | |
usage: | |
var anim = new ASCIIAnimation([":)",":|",":("], 100); | |
*/ | |
function ASCIIAnimation(animArray, speed) { | |
var currentFrame = 0; | |
for(var i = 0; i < animArray.length; i++) { | |
animArray[i] = animArray[i].replace(/ /g," "); | |
animArray[i] = animArray[i]; | |
} | |
document.title = animArray[0]; | |
currentFrame++; | |
this.animation = setInterval(function() { | |
document.title = animArray[currentFrame]; | |
currentFrame++; | |
if(currentFrame >= animArray.length) currentFrame = 0; | |
}, speed); | |
this.getCurrentFrame = function() { | |
return currentFrame; | |
} | |
} | |
ASCIIAnimation.prototype.stopAnimation = function() { | |
clearInterval(this.animation); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment