jQuery dequeue() 示例


jQuery 中的 dequeue() 方法用於從佇列中刪除下一個函式,然後執行該函式。

語法

語法如下 −

$(selector).dequeue(queue)

以上,queue 是佇列的名稱。

示例

現在讓我們看一個實現 jQuery dequeue() 方法 的示例 −

 現場演示

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("button").click(function(){
         var div = $("div");
         div.animate({height: 250}, "slow");
         div.animate({left: "+=200",top: "+=100" }, "slow");
         div.queue(function(){
            div.dequeue();
         });
         div.animate({height: 150}, "slow");
         div.animate({left: "10",top: "100" }, "slow");
      });
   });
</script>
<style>
div {
   width:150px;
   height:150px;
   position:absolute;
   left:10px;
   top:100px;
   background-color:orange;
}
</style>
</head>
<body>
<button>Begin</button>
<div></div>
</body>
</html>

輸出

這將生成以下輸出 −

現在,單擊“開始” −

現在,由於我們已經使用 dequeue,動畫就像初始形成 −

更新於:31-Dec-2019

170 次瀏覽

開啟你的職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.