jQuery jQuery.fx.off 屬性



jQuery 中的 jQuery.fx.off 屬性用於全域性停用或啟用所有 jQuery 動畫。它是一個布林屬性。預設值為 false,表示預設情況下啟用動畫。

將此屬性設定為 true 將停用所有動畫,使它們立即完成。

語法

以下是 jQuery jQuery.fx.off 屬性的語法:

jQuery.fx.off = true|false;

引數

以下是上述語法的描述:

  • true: 停用所有 jQuery 動畫。
  • false: 啟用所有 jQuery 動畫。

示例

此示例演示了使用“jQuery 的 jQuery.fx.off 屬性”切換動畫的開啟和關閉:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#disable").click(function(){
    jQuery.fx.off = true;
    $("#animationStatus").text("Animations: Disabled");
  });
  $("#enable").click(function(){
    jQuery.fx.off = false;
    $("#animationStatus").text("Animations: Enabled");
  });
  $("#toggle").click(function(){
    $("div").toggle("slow");
  });
});
</script>
</head>
<body>
<button id="disable">Animations: Disable (jQuery.fx.off = true)</button>
<button id="enable">Animations: Enabled (jQuery.fx.off = false)</button>
<br><br>
<button id="toggle">Toggle animation</button>

<p id="animationStatus">Animations: Enabled</p>

<div style="background:#98bf21;height:100px;width:100px;margin:50px;"></div>
</body>
</html>

“切換動畫”按鈕使用緩慢的動畫效果切換 div 的可見性。單擊“停用”將全域性關閉動畫,而單擊“啟用”將恢復動畫。

jquery_ref_properties.htm
廣告

© . All rights reserved.