I like Patrick's answer, but as an alternative, I would change the same letter in the text. And maybe rotate it a bit too (although this will not work in IE). I did a demonstration that I distributed with Patrick.
CSS
.newClass { left: 0px; top: -1px; color: red; position:relative; -webkit-transform: rotate(-5deg); -moz-transform: rotate(-5deg); }
the code
function randomLetter(cased){ // case = true for uppercase, false for lowercase var base = (cased) ? 65 : 97; // convert HTML escape code into a letter var rand = $('<span>&#' + parseInt(base+(Math.random()*25),10) + ';</span>'); return rand.text(); }; $(document).ready(function(){ var ltr = randomLetter(false); var reg = new RegExp( ltr, 'g'); $('#typehead').html(function(i,html){ return html.replace(reg, '<span class="newClass">' + ltr + '</span>'); }); });
Update: this is the code that needs to be applied to multiple h1 tags ( updated demo ):
function randomXToY(minVal,maxVal,floatVal){ var randVal = minVal+(Math.random()*(maxVal-minVal)); return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal); } $('.typehead').each(function() {
Mottie
source share