我对Javascript毫无希望.这就是我所拥有的:
它滚动到左边但我需要它相对无缝地重复.目前它只是跳回到开头.这可能不是我做的方式,如果没有,任何人都有更好的方法?
这是一个jQuery插件,具有很多功能:
http://jscroller2.markusbordihn.de/example/image-scroller-windiv/
而且这个"丝滑"
http://remysharp.com/2008/09/10/the-silky-smooth-marquee/
简单的JavaScript解决方案:
window.addEventListener('load', function () {
function go() {
i = i < width ? i + step : 1;
m.style.marginLeft = -i + 'px';
}
var i = 0,
step = 3,
space = ' ';
var m = document.getElementById('marquee');
var t = m.innerHTML; //text
m.innerHTML = t + space;
m.style.position = 'absolute'; // http://stackoverflow.com/questions/2057682/determine-pixel-length-of-string-in-javascript-jquery/2057789#2057789
var width = (m.clientWidth + 1);
m.style.position = '';
m.innerHTML = t + space + t + space + t + space + t + space + t + space + t + space + t + space;
m.addEventListener('mouseenter', function () {
step = 0;
}, true);
m.addEventListener('mouseleave', function () {
step = 3;
}, true);
var x = setInterval(go, 50);
}, true);
#marquee {
background:#eee;
overflow:hidden;
white-space: nowrap;
}
1 Hello world! 2 Hello world! 3 Hello world!