jqueryjquery-animatejquery-scrollable

scroll to top using .animate if at top stop - jquery


im using .animate to scroll to the top of the page, but if the user is already at the top or very near it and they click .proj-tile they wont be able to scroll down again for 1200ms is there a way to stop the script stop when the top is reached ?

 $('.proj-tile').click(function()   {
    $('html, body').animate({ scrollTop: '+0'   }, 1200);
});

cheers


Solution

  • Try adding a condition to check the height of the scroll and call the animate accordingly,

    $('.proj-tile').click(function()   {
        if($(window).scrollTop() >= 300) { //has scrolled considerably to animate
            $('html, body').animate({ scrollTop: '+0'   }, 1200);
        }
    });