学一个jquery方法,必须先从小例子学起,直接上一个简单的例子: 为了理解,这个例子只是在http://www.runoob.com/try/try.php?filename=tryjquery_eff_delay2 上面稍作修改
<!DOCTYPE html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function()
{
$("#btn1").click(function(){
$("div").animate({height:"200px"});
$("div").animate({width:"300px"});
$("div").delay(3200).animate({height:"300px"});
$("div").delay(1200).animate({width:"600px"});
});
});
</script>
</head>
<body>
<p>This example demonstrates the animate() method with three merged boxes.</p>
<p>The third box is set to delay() for 1200 milliseconds.</p>
<div style="background:purple;height:100px;width:100px;margin:6px;">
</div>
<p><button id="btn1">Animate</button></p>
</body>
</html>
需要注意的是,因为配合使用的是animate(),因此点击事件触发后,每一个执行代码都不是瞬发的,按照先后顺序,要等上一句执行代码动画执行完毕,才会执行下一句; 例如 $("div").animate({height:"200px"}); 这句的动画完全执行完,才会执行 $("div").animate({height:"200px"}); 这句