0

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

sam
  • 9,486
  • 36
  • 109
  • 160

1 Answers1

1

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);
    }
});
Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134