jQuery.fx.off

全局的禁用所有动画。

jQuery.fx.off

当这个属性设置为 true 的时候,调用时所有动画方法将立即设置元素为他们的最终状态,而不是显示效果。有时候确实有必要这样做:

  • jQuery是被用在低资源设备。
  • 动画使用户遇到可访问性问题(查看这篇文章获得更多信息 Turn Off Animation)。

动画可以通过设置这个属性为 false 重新打开。

例子

切换开启和关闭动画。

<!DOCTYPE html>
<html>
<head>
  <style>
    div { width:50px; height:30px; margin:5px; float:left;
          background:green; }
  </style>
  <script src="./static/js/jquery-3.5.0.js"></script>
</head>
<body>
  <p><input type="button" value="Run"/> <button>Toggle fx</button></p>
<div></div>
<script>
var toggleFx = function() {
  $.fx.off = !$.fx.off;
};
toggleFx();
 
$("button").click(toggleFx);
 
$("input").click(function(){
  $("div").toggle("slow");
});
  </script>
 
</body>
</html>

div

上篇: jQuery.speed