Animate scroll to ID on page load

前端 未结 6 2189
野性不改
野性不改 2020-11-28 01:39

Im tring to animate the scroll to a particular ID on page load. I have done lots of research and came across this:

$(\"html, body\").animate({ scrollTop: $(\         


        
6条回答
  •  春和景丽
    2020-11-28 01:39

    try with following code. make elements with class name page-scroll and keep id name to href of corresponding links

    $('a.page-scroll').bind('click', function(event) {
            var $anchor = $(this);
            $('html, body').stop().animate({
                scrollTop: ($($anchor.attr('href')).offset().top - 50)
            }, 1250, 'easeInOutExpo');
            event.preventDefault();
        });
    

提交回复
热议问题