Is there a way to make horizontal scrolling smoother

心已入冬 提交于 2019-11-30 21:53:05

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

Update

Here is another example of it wrapped into a function instead, bit easier to tweak the speed etc.

Fiddle

you can do it vertically with jquery although i'm sure it can be adjusted to be done horizontally. The demo is here

There's a javascript smoothscroll on github too added by cfernandi

Also ccheck out iscroll.js

$(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!