1

HTML部分:

<div id="container">

    <div id="box1" class="box">Div #1</div>
    <div id="box2" class="box">Div #2</div>
    <div id="box3" class="box">Div #3</div>
    <div id="box4" class="box">Div #4</div>
    <div id="box5" class="box">Div #5</div>

</div>

Javascript部分:

$('.box').click(function() {

    $(this).animate({
        left: '-50%'
    }, 500, function() {
        $(this).css('left', '150%');
        $(this).appendTo('#container');
    });

    $(this).next().animate({
        left: '50%'
    }, 500);
});​

CSS部分:

body {
    padding: 0px;    
}

#container {
    position: absolute;
    margin: 0px;
    padding: 0px;
    width: 100%;
    height: 100%;
    overflow: hidden;  
}

.box {
    position: absolute;
    width: 50%;
    height: 300px;
    line-height: 300px;
    font-size: 50px;
    text-align: center;
    border: 2px solid black;
    left: 150%;
    top: 100px;
    margin-left: -25%;
}

#box1 {
    background-color: green;
    left: 50%;
}

#box2 {
    background-color: yellow;
}

#box3 {
    background-color: red;
}

#box4 {
    background-color: orange;
}

#box5 {
    background-color: blue;
}
​

当上面的代码被编译并点击页面中的 div 时,它们会向左移动。我希望 div 朝相反的方向向右滑动。我知道这对于了解 jQuery 的人来说可能很容易,但我对这个脚本几乎一无所知,但我喜欢它的运行方式。链接到这个例子: http: //jsfiddle.net/jtbowden/ykbgT/2/ 感谢所有帮助。

4

2 回答 2

1
$('.box').click(function() {

    $(this).animate({
        left: '150%'
    }, 500, function() {
        $(this).css('left', '-150%');
        $(this).appendTo('#container');
    });

    $(this).next().css({
        left: '-150%'
    }, 500);
    $(this).next().animate({
        left: '50%'
    }, 500);
});​

http://jsfiddle.net/ykbgT/4148/

于 2012-11-19T05:48:57.027 回答
1
<div id="container">

<div id="box1" class="box">Div #1</div>
<div id="box2" class="box">Div #2</div>
<div id="box3" class="box">Div #3</div>
<div id="box4" class="box">Div #4</div>
<div id="box5" class="box">Div #5</div>

</div>


$('.box').click(function() {

$(this).animate({
    right: '-50%'
}, 500, function() {
    $(this).css('right', '150%');
    $(this).appendTo('#container');
});

$(this).next().animate({
    right: '50%'
}, 500);
});​


body {
padding: 0px;    
}

#container {
position: absolute;
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;  
}

.box {
position: absolute;
width: 50%;
height: 300px;
line-height: 300px;
font-size: 50px;
text-align: center;
border: 2px solid black;
right: 150%;
top: 100px;
margin-right: -25%;
}

#box1 {
background-color: green;
right: 50%;
}

#box2 {
background-color: yellow;
}

#box3 {
background-color: red;
}

#box4 {
background-color: orange;
}

#box5 {
background-color: blue;
}

​</p>

于 2012-11-19T05:52:20.970 回答