点击后左右移动?

时间:2011-08-18 08:26:43

标签: javascript jquery pagination jquery-animate

我的代码不起作用。我想要的是在点击#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);
    });
});

3 个答案:

答案 0 :(得分:0)

$('#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);
    });
});

答案 1 :(得分:0)

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

答案 2 :(得分:0)

您需要使用left而不是marginleft ... see here

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