任何人都可以帮我吗? 试图加入一个“慢”的功能与我smoothscroll和控制速度。
希望achievie一个真正的“smoothscrolling”。
下面是代码:
$(document).ready(function(){
$('.smoothscroll').live('click',function(e){
$('html,body').animate({
'scrollTop': $($(this).attr('href')).offset().top+'px'
});
e.preventDefault();
});
});
添加动画时间,第二个参数的.animate()
函数(后选择对象),如下所示:
$(document).ready(function(){
$('.smoothscroll').live('click',function(e){
$('html,body').animate({
'scrollTop': $($(this).attr('href')).offset().top+'px'
}, 10000);
e.preventDefault();
});
});
在该示例中,动画将采取万毫秒(10秒)。
感谢您的回答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();
});
});