按下“延时”按钮时动画并没有立刻停止,而是执行完水平移动以后再暂停设定时间,大家是这样吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>调用delay()方法延时执行动画效果</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h3>调用delay()方法延时执行动画效果</h3>
<span></span>
<input id="btnStop" type="button" value="延时" />
<div id="tip"></div>
<script type="text/javascript">
$(function () {
$("span").animate({
left: "+=100px"
}, 3000, function () {
$(this).animate({
height: '+=60px',
width: '+=60px'
}, 3000, function () {
$("#tip").html("执行完成!");
});
});
$("#btnStop").bind("click", function () {
$("span").delay(2000);
$("#tip").html("正在延时!");
});
});
</script>
</body>
</html>代码如上