需要将对象设置为顶部并使其返回

时间:2012-05-27 15:28:23

标签: javascript jquery html5

我需要我的飞机在跑道上飞行(这是地图)然后再点击。到目前为止它只会上升。     任何与java脚本/ html / jquery相关的东西。请简单的建议。 ty ^^     这是我目前的代码::

<div class="Map"><div id="MovingPlane1"></div></div>

JS:

<script type="text/javascript">
    $(document).ready(function(){
        $("#MovingPlane1").click(function(){
            $("#MovingPlane1").animate({bottom:"250px"},"slow");
        });
    });
<script>

3 个答案:

答案 0 :(得分:1)

jsBin demo

为您的飞机提供班级.plane并使用此代码:

$(".plane").click(function(){

   $(this).animate({bottom:250},800,function(){
       $(this).animate({bottom:0},800);
   });

});

在动画回调中你重做初始位置。

答案 1 :(得分:0)

尝试:

$(this).animate({bottom:"250px"},"slow",function(){
   $(this).animate({bottom:"0px"},"slow");
});

答案 2 :(得分:0)

如果您需要飞机在第二次点击时返回,请使用以下内容:

var plane1up = false;
$(document).ready(function(){
    $("#MovingPlane1").click(function(){
        $("#MovingPlane1").animate({bottom:(plane1up==true ? "0px" : "250px")},"slow");
    });
});