1 - 包括jQuery的项目(这wasnt包括小提琴) - 确保JS是在文件准备运行
2 - 作为修改的HTML如下:
<div id="scrollContainer">
<div id="content" style="white-space:nowrap; padding-left:600px;">134 1234 1234 12355 134 1234 1234 12355 134 1234 1234 12355 134 1234 1234 12355 134 1234 1234 12355 134 1234 1234 12355 134 1234 1234 12355 134 1234 1234 12355 134 1234 1234 12355</div>
</div>
3 - 使用这个js:
var $container = $("#scrollContainer");
var $content = $("#content");
containerWidth = $container.width();
contentWidth = $content.outerWidth();
contentLeft = 0;
scrollLeft = 0;
setInterval(function() {
if (scrollLeft > contentWidth + containerWidth)
scrollLeft = 0;
$container.scrollLeft(scrollLeft++);
}, 20);
它对我很好,然后在你的jsfiddle
错误'未捕获的ReferenceError:$未定义'。你没有包含jquery。 – anpsmn