jQuery中queue()方法用法实例

2020-05-23 06:06:13易采站长站整理

本文实例讲述了jQuery中queue()方法用法。分享给大家供大家参考。具体分析如下:

此方法能够显示或者操作在匹配元素上执行的函数队列。

此方法可能用的并不是太频繁,但是却非常的重要,下面就结合实例来介绍一下次方法的用法。
根据方法参数的不同,作用也有所不同。
说明:建议结合dequeue()函数一起学习。
语法结构一:
$(“selector”).queue(queueName)

参数列表:

参数描述
queueName可选。 第一个匹配元素上动画队列的名称,默认值是“fx”。

没有参数的时候,能够返回第一个匹配元素上的动画队列。

实例代码:


<!DOCTYPE html>
<html>
<head>
<meta charset=” utf-8″>
<meta name=”author” content=”//www.jb51.net/” />
<title>queue()函数-软件开发网</title>
<style type=”text/css”>
.box{
  width:300px;
  height:150px;
}
.mytest{
  width:50px;
  height:50px;
  background-color:green;
  position:absolute;
  left:0px;
  display:none;
  font-size:12px;

</style>
<script type=”text/javascript” src=”mytest/jQuery/jquery-1.8.3.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){
  $(“#do”).click(function(){
    $(“.mytest”).show(1000);
    $(“.mytest”).animate({left:”+=200″},3000);
    $(“.mytest”).animate({top:”+=50″},2000);
    $(“.mytest”).text(“动画完成”);
  })
  $(“#count”).click(function(){
    alert($(“.mytest”).queue().length)
  })
})
</script>
</head>
<body>
  <div class=”box”>
    <div class=”mytest”></div>