我有一段代码可以进行水平自动滚动,我用它在水平放置的滑块中显示一些图像。
下面是一个代码示例。
这段代码在台式机(pc)上运行得很好,但当我在手机上使用它时,它就不起作用了。它保持卡住状态,滚动条不移动。
有什么问题?
function animatethis(targetElement, speed) {
var scrollWidth = $(targetElement).get(0).scrollWidth;
var clientWidth = $(targetElement).get(0).clientWidth;
$(targetElement).animate({ scrollLeft: scrollWidth - clientWidth },
{
duration: speed,
complete: function () {
targetElement.animate({ scrollLeft: 0 },
{
duration: speed,
complete: function () {
animatethis(targetElement, speed);
}
});
}
});
};
animatethis($('#q1'), 5000);
# q1 { white-space: nowrap; overflow-y: scroll; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div id="q1">((BEGIN)) Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me Watch me ((END))</div>
暂无答案!
目前还没有任何答案,快来回答吧!