Jquery horizontal Scroll using buttons

前端 未结 3 1047
南方客
南方客 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 16:50

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

    Edit, to explain... you need to set its scroll left position.

    DEMO PLUNKR

提交回复
热议问题