2

任何人都可以帮助我吗?尝试使用我的平滑滚动和控制速度添加“慢”功能。

希望实现真正的“流畅滚动”。

以下是代码:

$(document).ready(function(){
$('.smoothscroll').live('click',function(e){
    $('html,body').animate({
    'scrollTop': $($(this).attr('href')).offset().top+'px'

    });
    e.preventDefault(); 
});

});
4

2 回答 2

1

将动画时间作为第二个参数添加到.animate()函数(在选项对象之后),如下所示:

$(document).ready(function(){
    $('.smoothscroll').live('click',function(e){
        $('html,body').animate({
            'scrollTop': $($(this).attr('href')).offset().top+'px'
        }, 10000);
        e.preventDefault(); 
    });
});

在此示例中,动画将花费 10,000 毫秒(10 秒)。

于 2012-06-19T00:16:40.663 回答
0

感谢nbsp的回答!

只为更新..

jQuery .live() 从 1.9 版本开始被移除。

所以这对我有用:

    $(document).ready(function() {
    $('.smoothscroll').on('click', 'a',function(e){
        $('html,body').animate({
            'scrollTop': $($(this).attr('href')).offset().top+'px'
        }, 10000);
        e.preventDefault();
    });
});
于 2015-11-08T19:22:15.647 回答