实现功能:
1、当点击按钮的时,移动页面上的某个元素(有时间制作)
Jquery代码:
<script type="text/javascript">
$(document).ready(function(){
$(".btn1").click(function(){
if(flag){
flag = false;
flag2 = true;
$("#box").css("display","block").animate({left:"-=100px"});
setTimeout($("#box").animate({left:"+=20px"}),30);
setTimeout($("#box").animate({left:"-=20px"}),30);
setTimeout($("#box").animate({left:"+=10px"}),30);
setTimeout($("#box").animate({left:"-=0px"}),30);
}
});
$(".btn2").click(function(){
if(flag2){
flag2 = false;
flag = true
$("#box").css("display","block").animate({left:"+=100px"});
setTimeout($("#box").animate({left:"-=20px"}),30);
setTimeout($("#box").animate({left:"+=20px"}),30);
setTimeout($("#box").animate({left:"-=10px"}),30);
setTimeout($("#box").animate({left:"+=0px"}),30);
}
});
});
var flag = true;
var flag2 = false;
</script>
代码解释:
HTML代码:
<body>
<div id="box" >
</div>
<button class="btn1">Animate</button>
<button class="btn2">Reset</button>
</body>
-----上传了源文件,有需要的自己下载下来看看吧!