jQuery: Scroll down page a set increment (in pixels) on click?

前端 未结 6 484
既然无缘
既然无缘 2020-12-07 18:48

I\'m trying to make a page scroll down 150px from the current position when an element is clicked. So lets say you\'re roughly halfway scrolled down a page. You click this

6条回答
  •  無奈伤痛
    2020-12-07 19:02

    Just check this:

    $(document).ready(function() {
        $(".scroll").click(function(event){
            $('html, body').animate({scrollTop: '+=150px'}, 800);
        });
    });
    

    It will make scroller scroll from current position when your element is clicked

    And 150px is used to scroll for 150px downwards

提交回复
热议问题