Your original code assumed that the 100%
width <span>
(i.e. 50%
inside the 200%
width <div>
) will accommodate the entire text.
I've modified it to actually calculate the width required by the string and then use that to do the animation.
Check this modified version: http://jsfiddle.net/yLwhe/5/
i.e.:
...
marquee.find("span").css({ ... });
// get the actual used width
var w = marquee.find("span").width();
...
var reset = function() {
$(this).css("margin-left", "0");
// use calculated width for animation.
$(this).animate({ "margin-left": "-"+w+"px" }, 40000, 'linear', reset);
};