jQuery中有哪些方法可以實現效果?


jQuery效果方法用於建立自定義動畫效果。以下是jQuery中一些用於提供效果的方法:

序號

方法
描述
1
animate()
對選定元素進行自定義動畫
2
clearQueue()
移除選定元素中剩餘的排隊函式
3
delay()
為選定元素上的所有排隊函式設定延遲
4
dequeue()
移除佇列中的下一個函式,然後執行該函式
5
fadeIn()
淡入選定元素
6
fadeOut()
淡出選定元素
7
fadeTo()
將選定元素淡入/淡出到給定的不透明度
8
fadeToggle()
在fadeIn()和fadeOut()方法之間切換
9
finish()
停止、移除並完成選定元素的所有排隊動畫

讓我們來看一個使用jQuery方法animate()的例子,它可以動畫化任何元素。

您可以嘗試執行以下程式碼,學習如何使用jQuery方法animate()來動畫化一個按鈕:

示例

線上演示

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
 $(document).ready(function(){
    $("#button1").click(function(){
      $("#shape").animate({width: "300px"});
    });
    $("#button2").click(function(){
      $("#shape").animate({width: "150px"});
    });
 });
</script>
</head>
<body>

<button id="button1">Increase width</button>
<button id="button2">Original width</button>

<div id="shape" style="background:rgb(73,159,255);height:150px;width:150px;margin:30px;"></div>

</body>
</html>

更新於:2020年6月12日

819 次瀏覽

啟動你的職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.