How to adjust speed of smoothScroll

混江龙づ霸主 提交于 2019-12-11 10:27:10

问题


I am currently using the smoothScroll function on a horizontally scrolling website. The current jQuery I have running is both for a previous/next section button and a regular navigation for all sections. The regular navigation is that with the .scroll-test class. This is the jQuery code:

$(document).ready(function() {
    var url = 1;

    $('a.forward').click(function () {
        url = url + 1;
        $(this).attr({ href: '#section' + url });
        $(this).parent().attr({ class: 'section' + url });
    });

    $('a.backward').click(function () {
        url = url - 1;
        $(this).attr({ href: '#section' + url });
        $(this).parent().attr({ class: 'section' + url });
    });

    $('a.forward, a.backward').smoothScroll();
    $('a.scroll-test').smoothScroll();
});

What I want is to change the speed of the scroll animation. Right now it's going really fast when jumping over more than one page.

Thanks in advance!


回答1:


Can't you set the speed by passing it a param (object) to the function like so

.smoothScroll({speed:2000})

The speed value is the animation time in milliseconds



来源:https://stackoverflow.com/questions/34154946/how-to-adjust-speed-of-smoothscroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!