首页 新闻 赞助 找找看

jQuery的delay方法为什么这样用没效果?

0
[已解决问题] 解决于 2012-04-05 08:19

我的代码:

<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<script src="jquery.min.js" type="text/javascript"></script>
<style type="text/css">
#test
{
width
:100px;
height
:100px;
background
:#CCC;
}
</style>
<script type="text/javascript">
$(
function(){
//$("#test").delay(2000).hide();
$("#test").show(500).delay(2000).hide(500);
//$("#test").show().delay(2000).hide();
});
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>

为什么用我注释掉的两种写法不行?

tab_china的主页 tab_china | 初学一级 | 园豆:54
提问于:2012-03-19 15:01
< >
分享
最佳答案
0

jQuery文档中已经说明了这个:

Only subsequent events in a queue are delayed; for example this will not delay the no-arguments forms of .show() or .hide() which do not use the effects queue.

在队列中的事件才能被delay

奖励园豆:5
dudu | 高人七级 |园豆:31075 | 2012-03-20 10:26
其他回答(2)
0

如果你隐藏的时候用hide,那么显示的时候就要用show.

悟行 | 园豆:12559 (专家六级) | 2012-03-19 15:58
$("#test").delay(2000).hide();这个为什么不行呢?
支持(0) 反对(0) tab_china | 园豆:54 (初学一级) | 2012-03-19 18:26
0

我觉得“最佳答案”没答到点上,动画效果本来默认就是在“fx”队列里的,“$("#test").show(500).delay(2000).hide(500);”事实上应该是可行的,我先hide再show的结果是可行。

菠菜变菠萝 | 园豆:202 (菜鸟二级) | 2012-12-03 12:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册