1

これはdivsliderの例のリンクです:http://jsfiddle.net/jtbowden/ykbgT/light/

しかし、この例では、divは右から左に移動しています

しかし、私は今、divを左から右に移動したいと思います。このウェブサイトにはすでにエディターがあります。だから私がdivを逆方向に動かすのを手伝ってください。私のコードでは両側に行きたいので

$('.box').click(function() {
    $('.box').each(function() {
        if ($(this).offset().left < 0) {
            $(this).css("left", "150%");
        } else if ($(this).offset().left > $('#container').width()) {
            $(this).animate({
                left: '50%',
            }, 500 );
        } else {
            $(this).animate({
                left: '-150%',
            }, 500 );
        }
    });
});​
4

2 に答える 2

0

これがあなたのJSフィドルで私のために働いたものです:

$('.box').click(function() {
    $('.box').each(function() {
        if ($(this).offset().left < 0) {
           $(this).animate({
                left: '50%',
            }, 500 );
        } else if ($(this).offset().left > $('#container').width()) {
            $(this).css({
                'left': '-150%',
            } );
        } else {
            $(this).animate({
                left: '150%',
            }, 500 );
        }
    });
});​
于 2012-10-31T03:19:47.333 に答える
0

これはどういう意味ですか?

#box1 {
    background-color: green;
    left: 150%; /* changed this */
}
#box3 {
    background-color: red;
    left: -150%; /* changed this */
}
​

$('.box').click(function() {
    $('.box').each(function() {
        if ($(this).offset().left > $('#container').width()) {
            $(this).css("left", "-150%");
        } else if ($(this).offset().left < 0) {
            $(this).animate({left:'50%'},500);
        } else {
            $(this).animate({left:'150%'},500);
        }
    });
});​
于 2012-10-31T04:20:47.413 に答える