jquery - How to add 'easing' to animate/scrolltop -
i using following function create scroll animation anchor links:
$('a').click(function(){ $('html, body').animate( {scrolltop: $( $.attr(this, 'href') ).offset().top}, 500 ); return false; }); i add easing. however, when add 'easing' after '500' breaks script:
$('a').click(function(){ $('html, body').animate( {scrolltop: $( $.attr(this, 'href') ).offset().top}, 500, easing ); return false; }); any ideas doing wrong?
first need include jquery.ui script code should look:
$('a').click(function(){ var top = $('body').find($(this).attr('href')).offset().top; $('html, body').animate({ scrolltop: top },500, 'easeoutexpo'); return false; }); for information:
easing
the remaining parameter of .animate() string naming easing function use. easing function specifies speed @ animation progresses @ different points within animation. easing implementations in jquery library default, called swing, , 1 progresses @ constant pace, called linear. more easing functions available use of plug-ins, notably jquery ui suite.
why code not working:
- because use
thisin scope of animation method , referencebody,htmlobjects. - because
easingnot method. string type of animation property need write string example:'easeoutexpo'or"easeoutexpo".
Comments
Post a Comment