JQuery scrolltop - not working after first use

I am using jQuery scrolltop function on this menu: http://goethesternfriseure.de/index.php

the problem is that the scroll function only works the first time. after the second click on the link, it scrolls to the very bottom.

$('.sectionlink').click(function(e){
            var sectionelement = $(this).attr("rel");
            var myoffset = $('#'+sectionelement).offset().top;
            $('html, body').animate({
                scrollTop: myoffset
            }, 800);

            e.preventDefault();
        });

      

Does anyone know what's going on there?

+3


source to share


1 answer


the top of the scroll doesn't work because you need to add "px":



$('.sectionlink').click(function(e){
            var sectionelement = $(this).attr("rel");
            var myoffset = $('#'+sectionelement).offset().top;
            $('html, body').animate({
                scrollTop: myoffset+"px"
            }, 800);

            e.preventDefault();
        });

      

+1


source







All Articles