jQuery的Smoothscroll功能 - 如何控制动画速度? [英] Jquery Smoothscroll Function - How to Control Animation Speed?

查看:155
本文介绍了jQuery的Smoothscroll功能 - 如何控制动画速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮我吗?尝试添加一个慢的功能与我smoothscroll和控制速度。

Anyone can help me? Trying to Add a "Slow" function with my smoothscroll and control speed.

希望能achievie一个真正的smoothscrolling。

Hope to achievie a real "smoothscrolling".

下面是codeS:

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

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

});

谢谢!

推荐答案

添加动画时间,第二个参数的 .animate()函数(后选择对象)像这样:

Add the animation time as the 2nd parameter to the .animate() function (after the options object) like so:

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

在这个例子中,动画将采取万毫秒(10秒)。

In this example the animation will take 10,000 ms (10 seconds).

这篇关于jQuery的Smoothscroll功能 - 如何控制动画速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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