es una forma bastante simple de hacer aquí. En primer lugar, establecer un div que contiene el texto largo:
<div id="container">
Here is the long content, long long content. So long. Too long.
</div>
Se puede utilizar un poco de CSS para manejar automáticamente el truncamiento y puntos suspensivos:
div#container {
/* among other settings: see fiddle */
width: 200px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
Si a continuación, determinar el ancho nativa, no truncado del contenido , puede usar jQuery's .animate()
para mover ese contenido a una velocidad constante, incluso si no conoce la longitud del texto hasta el tiempo de ejecución (como sería el caso con un feed de Twitter). Aquí está una manera un tanto mecánica de conseguir la medición:
var true_width = (function(){
var $tempobj = $('#container') // starting with truncated text div container
.clone().contents() // duplicate the text
.wrap('<div id="content"/>') // wrap it in a container
.parent().appendTo('body') // add this to the dom
.css('left','-1000px'); // but put it far off-screen
var result = $tempobj.width(); // measure it
$tempobj.remove(); // clean up
return result;
})();
Por último, un poco de animación:
$('#container').one('mouseenter', function(){ // perhaps trigger once only
var shift_distance = true_width - $(this).width(); // how far to move
var time_normalized = parseInt(shift_distance/100, 10) * 1000; // speed
$(this).contents().wrap('<div id="content">').parent() // wrap in div
.animate({
left: -shift_distance,
right: 0
}, time_normalized, 'linear'); // and move the div within its "viewport"
});
Sin importar la longitud del texto, obtendrá una velocidad constante de aproximadamente un segundo por 100 píxeles (ajustar según lo deseado). Restablecer o rebobinar contenido en mouseleave se deja como un ejercicio. Este enfoque tiene algunas partes ingenuas, pero puede darte algunas ideas.
Aquí está un ejemplo de trabajo: http://jsfiddle.net/redler/zdvyj/
gracias por el violín :) y el gran expl anatory comments – Purefan