Toggle animation on and off:
When the "Toggle animation" button is pressed, we toggle between hiding and showing the div.
Press "Enable" or "Disable" to turn animations on and off.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#disable").click(function(){ jQuery.fx.off = true;/*from www.j a v a 2 s . c o m*/ }); $("#enable").click(function(){ jQuery.fx.off = false; }); $("#toggle").click(function(){ $("div").toggle("slow"); }); }); </script> </head> <body> <button id="disable">jQuery.fx.off = true ( Disable )</button> <button id="enable">jQuery.fx.off = false ( Enable )</button> <br><br> <button id="toggle">Toggle animation</button> <div style="background:#98bf21;height:100px;width:100px;margin:50px;"></div> </body> </html>
The jQuery.fx.off property globally disable/enable all animations.
Default value is false, which allows animations to run normally.
When set to true, all animation methods will be disabled.
It will immediately set elements to their final state, instead of displaying an effect.
jQuery.fx.off = true|false;
Parameter | Description |
---|---|
true | animations should be disabled |
false | Default. animations should be enabled |