有没有办法使水平滚动更流畅 [英] Is there a way to make horizontal scrolling smoother
本文介绍了有没有办法使水平滚动更流畅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
This fiddle is almost what I'm looking for, I got it from MDN. The only thing missing is that I want to make it smoother. Is there a way to do that without using jQuery or any other plugins?
var button = document.getElementById('slide');
button.onclick = function () {
document.getElementById('container').scrollLeft += 100;
};
var back = document.getElementById('slideBack');
back.onclick = function () {
document.getElementById('container').scrollLeft -= 100;
};
推荐答案
这大概可以优化,但这是一个使用setInterval
和clearInterval
This could probably be optimised a fair bit, but here is a basic example of how you could do it using setInterval
and clearInterval
Fiddle
更新
这是将其包装到函数中的另一个示例,可以更容易地调整速度等.
Here is another example of it wrapped into a function instead, bit easier to tweak the speed etc.
这篇关于有没有办法使水平滚动更流畅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文