jQuery jQuery.fx.interval 属性
实例
使 <div> 元素的动画以较少的帧数运行:
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#toggle").on("click", function(){
$("div").toggle(5000);
});
$("#interval").on("click", function(){
jQuery.fx.interval = 500;
});
});
</script>
</head>
<body>
<p>When the "Toggle div" button is pressed, we toggle between hiding and showing the div (default is 13 milliseconds). Each time the "Run animation with less frames" button is pressed, we add 500 milliseconds to the property, which causes the animation to run with less frames (depending on the browser, this may cause the animation to run less smoothly than desired).</p>
<p><b>Note:</b> Since jQuery uses one global interval, for any changes to this property to take effect, no animation should be running or all animations should be stopped first (press "Toggle div". Then press "Run animation with less frames" when "div" is finished with the animation. When the animation has stopped, press "Toggle div" again to notice the effect).</p>
<button id="toggle">切换 div</button>
<button id="interval">用较少帧数运行</button>
<div style="background:#98bf21;height:100px;width:100px;margin:50px;"></div>
</body>
</html>
定义与用法
jQuery.fx.interval
属性用于以毫秒为单位更改动画触发速率。
默认值为 13 毫秒。此属性通常用于修改每秒运行动画的帧数。降低发射率可以使动画运行更平滑。但是,它可能会影响性能和 CPU。
注意:要使此属性的任何更改生效,不应运行任何动画,或者应先停止所有动画。
注意:此属性在支持 requestAnimationFrame
属性的浏览器中无效。
语法
jQuery.fx.interval = milliseconds;
参数 | 描述 |
---|---|
milliseconds | 必填。以毫秒为单位指定动画触发速率。默认值为 13 毫秒 |