您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年09月10日 08:09

原创 jQuery.clearQueue() 函数详解

2243 次浏览 读完需要≈ 4 分钟

内容目录

clearQueue()函数用于清空每个匹配元素的指定队列中所有尚未执行的项。

该函数属于jQuery对象(实例)。

语法

jQuery 1.4 新增该函数。

jQueryObject.clearQueue( [ queueName ] )

参数

参数 描述
queueName 可选/String类型指定的队列名称,默认为"fx"(表示jQuery中的标准动画效果队列)。

返回值

clearQueue()函数的返回值是jQuery类型,返回当前jQuery对象本身。

示例&说明

以下面这段HTML代码为例:

<input id="start" type="button" value="开始队列" />
<input id="stop" type="button" value="清空队列" />
<div id="n1" style="width: 200px; height: 100px; border: 1px solid #ccc;" ></div>
<div id="n2" style="width: 200px; height: 100px; border: 1px solid #ccc;" ></div>
<div id="n3" style="width: 200px; height: 100px; border: 1px solid #ccc;" ></div>

我们编写如下jQuery代码:

var $divs = $("div");

$("#start").click(function(){
	// 为每个div元素设置3个自定义动画
	$divs.animate( {width: 400, height: 200}, 1000 )
	.animate( { width: 800, height: 400 }, 1000 )
	.animate( { width: 200, height: 100 }, 2000 );
});

$("#stop").click(function(){
	// 清空默认的动画队列
	// 队列中所有尚未执行的函数都将被清空
	$divs.clearQueue();
});

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单