Jquery horizontal Scroll using buttons

前端 未结 3 1050
南方客
南方客 2020-12-05 16:41

I am trying to obtain horizontal scroll using buttons.

I have a container which has several divs stacked horizontally and I want to scroll through them using the but

3条回答
  •  不知归路
    2020-12-05 17:02

    You are looking for scrollLeft not marginLeft:

    $('#right-button').click(function() {
      event.preventDefault();
      $('#content').animate({
        scrollLeft: "+=200px"
      }, "slow");
    });
    
     $('#left-button').click(function() {
      event.preventDefault();
      $('#content').animate({
        scrollLeft: "-=200px"
      }, "slow");
    });
    

    Demo: http://plnkr.co/edit/ZdCw7IEYdV5YVeGg33oX?p=preview

提交回复
热议问题