I'm pretty new to jQuery but I've managed to find/combine something that does what I want to achieve.
The script replaces a word in a text/headline in a loop. It fades Out, updates the text and fades In again - but my problem is: that the sentence, getting shorter or longer, causes a jumping of the headline or a whole paragraph.
Heres my Code on jsFiddle http://jsfiddle.net/B2eLz/1/
Is there a way to implement a smooth animation that stops the sentence/paragraph from jumping?
Thanks
JS:
$(function(){
var words = [
'breathtaking',
'excellent',
'awesome',
'nice',
'cool',
'sweet',
'extraordinary'
], i = 0; // i for counting
setInterval(function(){
$('span').fadeOut(function(){ //fadeout text
$(this).html(words[i=(i+1)%words.length]).fadeIn(); //update, count and fadeIn
});
}, 2000 ); //2s
});
HTML:
<h3>This is a <span>extraordinary</span> Headline in a h3-Tag</h3>