有没有办法使水平滚动更流畅 [英] Is there a way to make horizontal scrolling smoother

查看:86
本文介绍了有没有办法使水平滚动更流畅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个小提琴几乎是我要找的东西,我从

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;
        };

推荐答案

这大概可以优化,但这是一个使用setIntervalclearInterval

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆