jQuery $.fx.off: How to Disable Animations
The $.fx.off property in jQuery is a global
configuration setting used to completely disable all animations and
visual transitions across an entire webpage. When enabled, elements
animated via jQuery immediately snap to their final state without
rendering intermediate frames. This article explains how the
$.fx.off property works, provides practical code examples,
and highlights the primary scenarios where disabling animations is
beneficial, such as automated testing and user accessibility.
Understanding $.fx.off
By default, jQuery’s $.fx.off property is set to
false, allowing all animation functions—including
.animate(), .fadeIn(),
.slideDown(), and .hide()—to run with their
designated easing and duration.
When $.fx.off is set to true:
- All animation effects are instantly turned off.
- Any ongoing or newly triggered animations bypass their duration timers.
- Elements instantly jump directly to their final CSS styles and visibility states.
Syntax and Implementation
To toggle the property, access it directly on the global jQuery object:
// Globally disable all jQuery animations
$.fx.off = true;
// Re-enable all jQuery animations
$.fx.off = false;Example Usage
// Disable animations globally
$.fx.off = true;
// This will show the div immediately, without any 1-second fade effect
$("#alert-box").fadeIn(1000);Primary Use Cases
1. Automated Testing (Unit and Integration Tests)
Animations introduce timing dependencies and asynchronous delays that
can make automated browser tests (such as Selenium, Cypress, or QUnit)
slow and flaky. Setting $.fx.off = true inside a test suite
ensures that DOM changes happen synchronously and immediately,
eliminating the need for arbitrary wait times and significantly speeding
up test runs.
2. Accessibility (Reduced Motion Support)
Users who experience vestibular disorders or motion sensitivity often
configure their operating systems to minimize visual motion. You can use
$.fx.off to honor the CSS
prefers-reduced-motion media query:
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
$.fx.off = true;
}3. Low-Resource or Legacy Devices
Running complex JavaScript animations on low-power devices can lead
to high CPU usage, stuttering, and dropped frames. Toggling
$.fx.off on specific hardware profiles helps preserve
performance and battery life by skipping non-essential rendering
work.