【问题标题】:moved to left and right after click?点击后左右移动?
【发布时间】:2011-08-18 16:47:12
【问题描述】:

我的代码不起作用。我想要的是在单击#prev_pag#next_pag 后将分页向左和向右移动。我不知道为什么这段代码不起作用?

示例: http://jsfiddle.net/szVKD/

JS代码:

$('#next_pag').click(function() {
        $('#pagination').animate({
            marginLeft: '-=100px'
        },
        500);
    });
    $('#prev_pag').click(function() {
        $('#pagination').animate({
            marginLeft: '+=100px'
        },
        500);
    });
});

【问题讨论】:

  • 我认为你需要使用left 而不是marginLeft
  • 包含一个 jsfiddle 做得很好,但如果它确实显示了一些内容并证明了问题,那就太好了。

标签: javascript jquery pagination jquery-animate


【解决方案1】:

尝试动画不是'marginLeft'而是'left'; 示例: http://www3.montonfashion.com/js/slider/carouselPP.js http://www3.montonfashion.com/et/waistcoat-willy.html

【讨论】:

    【解决方案2】:

    你需要玩left而不是marginleft...see here

    $('#next_pag').click(function() {
            $('#pagination').animate({
                left: '-=100px'
            },
            500);
        });
        $('#prev_pag').click(function() {
            $('#pagination').animate({
                left: '+=100px'
            },
            500);
        });
    });
    

    【讨论】:

      【解决方案3】:
      $('#next_pag').click(function(e) {
               e.preventDefault(); //prevent the default behaviour
              $('#pagination').animate({
                  left: '-=100px'
              },
              500);
          });
          $('#prev_pag').click(function(e) {
              e.preventDefault(); //prevent the default behaviour
              $('#pagination').animate({
                  left: '+=100px'
              },
              500);
          });
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-15
        • 1970-01-01
        • 1970-01-01
        • 2013-09-01
        • 2022-11-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多