问题
Anyone can help me? Trying to Add a "Slow" function with my smoothscroll and control speed.
Hope to achievie a real "smoothscrolling".
Here are the codes:
$(document).ready(function(){
$('.smoothscroll').live('click',function(e){
$('html,body').animate({
'scrollTop': $($(this).attr('href')).offset().top+'px'
});
e.preventDefault();
});
});
回答1:
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();
});
});
In this example the animation will take 10,000 ms (10 seconds).
回答2:
Thanks for the answer nbsp!
Just to update..
jQuery .live() has been removed in version 1.9 onwards.
so here what worked for me :
$(document).ready(function() {
$('.smoothscroll').on('click', 'a',function(e){
$('html,body').animate({
'scrollTop': $($(this).attr('href')).offset().top+'px'
}, 10000);
e.preventDefault();
});
});
来源:https://stackoverflow.com/questions/11092794/jquery-smoothscroll-function-how-to-control-animation-speed