Problems with scrollTop

Problems with scrollTop

    Hello everybody,

    I have the following code which scrolls the page to the top if you press a link in my menu.

    The thing is I would only like this to work if the page is not at the top. So if the page already is at the top then it should not have any effect. How can I do that? 

    1. $(document).ready(function(){

    2. // scroll body to 0px on click
    3. $('.red ul.mega-menu li a').click(function () {
    4. $('body,html').animate({
    5. scrollTop: 0
    6. }, 800);
    7. return false;
    8. });
    9. });

    Best regards,
    Lasse
      • Topic Participants

      • lasse