Although moxn has done all the hard work for you, I suppose what you are really after is a jquery-fied version of that...
So here is a jquery plugin, thanks moxn for original code, all I did was convert it to a jquery plugin
(function($){
$.fn.generateHeader=function(settings){
var settings=$.extend({
newText:"This is a new header"
},settings);
return this.each(function(){
var _this=$(this)[0];
changeHeader(_this, settings.newText);
function createRandomString(length, node, callback, value) {
if (typeof value == "undefined"){
value = "";
}
if (value.length == length){
callback(value);
return;
}
var c = ((Math.round(Math.random() * 100)) % 127);
if (c == '\'' || c == '\"'){
c = 33;
}
value += String.fromCharCode(Math.max(33, c));
node.innerHTML = value;
setTimeout(function(){createRandomString(length, node, callback, value)}, 20);
}
function changeHeader(node, realString, randomString){
if (typeof randomString == "undefined") {
createRandomString(realString.length, node, function(value){changeHeader(node, realString, value);});
return;
}
var d = realString.length - randomString.length;
var modifiedString = realString.substring(0, d) + randomString;
node.innerHTML = modifiedString;
if (randomString.length == 0){
return;
}
randomString = randomString.substring(1);
setTimeout(function(){changeHeader(node,realString,randomString);}, 50);
}
});
};
})(jQuery);
You would use it by first including the above code somewhere in your html...
and then calling something like $('#heading').generateHeader({newText:'this is the new header text'});
where heading
is the id of the element you would want to apply this to, and then change 'this is the new header text'
to whatever text you would want to show up...