scroll up and down a div on button click using jquery

前端 未结 7 1462
梦毁少年i
梦毁少年i 2020-12-02 15:14

I am trying to add a feature to scroll up and down a div based on button click. I was able to do the scroll down part easily, but got stuck wit the scroll up part and one mo

7条回答
  •  甜味超标
    2020-12-02 15:32

    Just to add to other comments - it would be worth while to disable scrolling up whilst at the top of the page. If the user accidentally scrolls up whilst already at the top they would have to scroll down twice to start

    if(scrolled != 0){
      $("#upClick").on("click" ,function(){
         scrolled=scrolled-300;
            $(".cover").animate({
              scrollTop:  scrolled
         });
      });
    }
    

提交回复
热议问题