jQuery .scrollTop(); + animation jQuery .scrollTop(); + animation jquery jquery

jQuery .scrollTop(); + animation


To do this, you can set a callback function for the animate command which will execute after the scroll animation has finished.

For example:

var body = $("html, body");body.stop().animate({scrollTop:0}, 500, 'swing', function() {    alert("Finished animating");});

Where that alert code is, you can execute more javascript to add in further animation.

Also, the 'swing' is there to set the easing. Check out http://api.jquery.com/animate/ for more info.


Try this code:

$('.Classname').click(function(){    $("html, body").animate({ scrollTop: 0 }, 600);    return false;});


Use this:

$('a[href^="#"]').on('click', function(event) {    var target = $( $(this).attr('href') );    if( target.length ) {        event.preventDefault();        $('html, body').animate({            scrollTop: target.offset().top        }, 500);    }});