Transitions
The jQuery Mobile framework includes a set of CSS-based transition effects that can be applied to any page link or form submission with Ajax navigation.
Page transitions
fade |
dialog | page |
---|---|---|
pop |
dialog | page |
flip |
dialog | page |
turn |
dialog | page |
flow |
dialog | page |
slidefade |
dialog | page |
slide |
dialog | page |
slideup |
dialog | page |
slidedown |
dialog | page |
none |
dialog | page |
Important: Some platforms currently have issues with transitions. We are working on a solution to solve the problem for everyone. If you are experiencing flickers and flashes during or at the end of a transition we suggest the following workaround. Please note that this workaround should be thoroughly tested on the target platform before deployment. This workaround is known to cause performance issues and browser crashes on some platforms, especially Android. Add the following code to your custom css:
.ui-page { -webkit-backface-visibility: hidden; }
Only seeing fade transitions? To view all transition types, you must be on a browser that supports 3D transforms. By default, devices that lack 3D support (such as Android 2.x) will fallback to "fade" for all transition types. This behavior is configurable (see below).
Transitions were originally inspired by jQtouch They've since been rebuilt, but props to David Kaneda and Jonathan Stark for the initial guidance.
Setting a transition
By default, the framework applies a fade transition. To set a custom transition effect, add the data-transition
attribute to the link.
<a href="index.html" data-transition="pop">I'll pop</a>
When the Back button is pressed, the framework will automatically apply the reverse version of the transition that was used to show the page. To specify that the reverse version of a transition should be used, add the data-direction="reverse"
attribute to a link. Note: data-direction="reverse"
attribute can only be used with page and dialog.
Global configuration
Set the defaultPageTransition
global option if you'd prefer a different default transition. Dialogs have a different option called defaultDialogTransition
that can also be configured.
Note: since the dialog widget is deprecated as of jQuery Mobile 1.4.0, the $.mobile.defaultDialogTransition
global option is also deprecated and will be removed.
Browser support
All transitions are built with CSS keyframe animations and include -webkit
vendor prefixed rules for iOS, Blackberry, Android, Safari and Chrome browsers, -moz
rules for Firefox browsers, and unprefixed rules for Windows Phone 8 and IE10. Support for keyframe animations and transition smoothness is determined by the browser version and hardware and will safely fall back to no transition if animations aren't supported. To proactively exclude transition in situations with poor performance, we exclude browsers that lack 3D transforms and provide a fallback transition and apply a max width for when transitions are applied.
Fallback transition
By default, all transitions except fade require 3D transform support. Devices that lack 3D support will fall back to a fade transition, regardless of the transition specified. We do this to proactively exclude poorly-performing platforms like Android 2.x from advanced transitions and ensure they still have a smooth experience. Note that there are platforms such as Android 3.0 that technically support 3D transforms, but still have poor animation performance so this won't guarantee that every browser will be 100% flicker-free but we try to target this responsibly.
The fallback transition for browsers that don't support 3D transforms can be configured for each transition type, but by default we specify "fade" as the fallback. For example, this will set the fallback transition for the slideout transition to "none":
$.mobile.transitionFallbacks.slideout = "none"
Max scroll for transitions
By default, transitions are disabled (set to "none") when you're either coming FROM or going TO a page where the scroll position is 3x the height of the device's screen.
This feature was added because of the slow response times and the possibility of browser crashing when clicking on a list item (or any navigation element) far down a long page which leads to the
browser trying to animate a really massively tall page from the scroll position to the top of the screen. The scroll position, not total screen height, is the determining factor for performance.
This scroll position breakpoint is configurable via the new getMaxScrollForTransition
function.
Max width for transitions
By default, transitions can be disabled (set to "none") when the window width is greater than a certain pixel width. This feature is useful because transitions can be distracting or perform poorly on larger screens. This value is configurable via the global option $.mobile.maxTransitionWidth
, which defaults to false
. The option accepts any number representing a pixel width or false
value. If it's not false
, the handler will use a "none" transition when the window is wider than the specified value.
Same page transition
Transitions to the current active page are ignored by default but can be enabled by using the allowSamePageTransition
option of the pagecontainer widget's change()
method. Note that not all transitions will work as expected and may end in an impractical result.
Creating custom transitions
jQuery Mobile allows for the addition of custom transitions to the $.mobile.transitionHandlers
dictionary so you can expand the selection of transitions on your site or app.