I have a function (see below) that writes a message out onto the screen. Whenever you're actively viewing the page that it is running on, it prints out just fine; however, say you're watching a video in another tab and switch back to the tab that is writing out the function, the text comes out all jumble. e.g: "This is a message." generally would come out scrambled like "t isa hismg esseg."
The function in question:
params:
message: string
object: an HTML Object
function writeMessage(message,object){
var i = 0;
var interval = setInterval(function(){
if(i < message.length){
object.append(message.substr(i,1));
i++;
}else{
clearInterval(interval);
}
}, 25);
}
Any idea as to why this happens?