<body onload='boot();'>
<div id='container'>
<h1>Jquery Typewriter</h1>
<div id='main'>
<p><a href='#' onclick='$("#typewriter").typewriter(); return false;'>Run demo</a></p>
<div id='typewriter'>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
</div>
</body>
JavaScript
function shuffle(a) {
var i = a.length, j;
while (i) {
var j = Math.floor((i--) * Math.random());
var t = a[i];
a[i] = a[j];
a[j] = t;
}
}
function randomAlphaNum() {
var rnd = Math.floor(Math.random() * 62);
if (rnd >= 52) return String.fromCharCode(rnd - 4);
else if (rnd >= 26) return String.fromCharCode(rnd + 71);
else return String.fromCharCode(rnd + 65);
}
$.fn.rot13 = function() {
this.each(function() {
$(this).text($(this).text().replace(/[a-z0-9]/ig, function(chr) {
var cc = chr.charCodeAt(0);
if (cc >= 65 && cc <= 90) cc = 65 + ((cc - 52) % 26);
else if (cc >= 97 && cc <= 122) cc = 97 + ((cc - 84) % 26);
else if (cc >= 48 && cc <= 57) cc = 48 + ((cc - 43) % 10);
return String.fromCharCode(cc);
}));
});
return this;
};
$.fn.scrambledWriter = function() {
this.each(function() {
var $ele = $(this), str = $ele.text(), progress = 0, replace = /[^\s]/g,
random = randomAlphaNum, inc = 3;
$ele.text('');
var timer = setInterval(function() {
$ele.text(str.substring(0, progress) + str.substring(progress, str.length).replace(replace, random));
progress += inc
if (progress >= str.length + inc) clearInterval(timer);
}, 100);
});
return this;
};
$.fn.typewriter = function() {
this.each(function() {
var $ele = $(this), str = $ele.text(), progress = 0;
$ele.text('');
var timer = setInterval(function() {
$ele.text(str.substring(0, progress++) + (progress & 1 ? '_' : ''));
if (progress >= str.length) clearInterval(timer);
}, 100);
});
return this;
};
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.