{"id":960,"date":"2012-05-02T23:12:58","date_gmt":"2012-05-03T06:12:58","guid":{"rendered":"http:\/\/zsprawl.com\/iOS\/?p=960"},"modified":"2012-10-05T19:24:24","modified_gmt":"2012-10-06T02:24:24","slug":"fixing-the-transitions-in-jquery-mobile-1-1-0","status":"publish","type":"post","link":"http:\/\/zsprawl.com\/iOS\/2012\/05\/fixing-the-transitions-in-jquery-mobile-1-1-0\/","title":{"rendered":"Fixing the Transitions in jQuery Mobile 1.1.0"},"content":{"rendered":"<p>Well, reverting back to the jQuery Mobile 1.0.1 transitions isn&#8217;t really &#8220;fixing&#8221; things per say but&#8230;<\/p>\n<p>A very hot topic in the community are the improved page transitions effects included in jQuery Mobile&#8217;s 1.1.0 release. In the previous major release 1.0.1, these page animations &#8211; slide, slideup, flip, pop &#8211; performed poorly on certain Android devices. To improve transition effects for devices overall, the developers moved to a two step process. All animations are now queued to first perform the pageOut sequence and then the pageIn sequence. <\/p>\n<p>This effect creates a noticable break in the previously smoother animations, but the performance is greatly improved on smaller devices, so the tradeoff is considered good. To help mask a bit of this break, a fade effect was added, which unfortunately for some has created a noticeable flash effect.<\/p>\n<p>Anyhow, that is all good, but for us that don&#8217;t care to support these slower devices, the older page transitions from jQuery Mobile 1.0.1 are much nicer to the eye. How do we revert things back without resorting to using the older version? It&#8217;s actually pretty simple once I started digging around.<\/p>\n<p>First, we need to tell jQuery Mobile&#8217;s javascript function to run both the pageOut and pageIn functions at the same time. This is rather easy. <del datetime=\"2012-05-04T18:30:12+00:00\">Open jquery.mobile-1.1.0.js and scroll down to the createHandler function on line 2181 and add:<\/del>. Copy and paste the following Javascript into a js file. I called mine utility.js.<\/p>\n<p>[code]<br \/>\n$(document).bind( &#8220;mobileinit&#8221;, function(event) {<br \/>\n\t$.mobile.transitionHandlers = { &#8220;default&#8221; : $.mobile.defaultTransitionHandler };<br \/>\n});<\/p>\n<p>$(document).bind(&#8220;mobileinit&#8221;, function(){<br \/>\n\t$.mobile.defaultTransitionHandler = function( name, reverse, $to, $from ) {<\/p>\n<p>\t\tvar deferred = new $.Deferred(),<br \/>\n\t\t\tsequential = false,<br \/>\n\t\t\treverseClass = reverse ? &#8221; reverse&#8221; : &#8220;&#8221;,<br \/>\n\t\t\tactive\t= $.mobile.urlHistory.getActive(),<br \/>\n\t\t\ttoScroll = active.lastScroll || $.mobile.defaultHomeScroll,<br \/>\n\t\t\tscreenHeight = $.mobile.getScreenHeight(),<br \/>\n\t\t\tmaxTransitionOverride = $.mobile.maxTransitionWidth !== false &#038;&#038; $( window ).width() > $.mobile.maxTransitionWidth,<br \/>\n\t\t\tnone = !$.support.cssTransitions || maxTransitionOverride || !name || name === &#8220;none&#8221;,<br \/>\n\t\t\ttoggleViewportClass = function(){<br \/>\n\t\t\t\t$.mobile.pageContainer.toggleClass( &#8220;ui-mobile-viewport-transitioning viewport-&#8221; + name );<br \/>\n\t\t\t},<br \/>\n\t\t\tscrollPage = function(){<br \/>\n\t\t\t\t\/\/ By using scrollTo instead of silentScroll, we can keep things better in order<br \/>\n\t\t\t\t\/\/ Just to be precautios, disable scrollstart listening like silentScroll would<br \/>\n\t\t\t\t$.event.special.scrollstart.enabled = false;<\/p>\n<p>\t\t\t\twindow.scrollTo( 0, toScroll );<\/p>\n<p>\t\t\t\t\/\/ reenable scrollstart listening like silentScroll would<br \/>\n\t\t\t\tsetTimeout(function() {<br \/>\n\t\t\t\t\t$.event.special.scrollstart.enabled = true;<br \/>\n\t\t\t\t}, 150 );<br \/>\n\t\t\t},<br \/>\n\t\t\tcleanFrom = function(){<br \/>\n\t\t\t\t$from<br \/>\n\t\t\t\t\t.removeClass( $.mobile.activePageClass + &#8221; out in reverse &#8221; + name )<br \/>\n\t\t\t\t\t.height( &#8220;&#8221; );<br \/>\n\t\t\t},<br \/>\n\t\t\tstartOut = function(){<br \/>\n\t\t\t\t\/\/ if it&#8217;s not sequential, call the doneOut transition to start the TO page animating in simultaneously<br \/>\n\t\t\t\tif( !sequential ){<br \/>\n\t\t\t\t\tdoneOut();<br \/>\n\t\t\t\t}<br \/>\n\t\t\t\telse {<br \/>\n\t\t\t\t\t$from.animationComplete( doneOut );<br \/>\n\t\t\t\t}<\/p>\n<p>\t\t\t\t\/\/ Set the from page&#8217;s height and start it transitioning out<br \/>\n\t\t\t\t\/\/ Note: setting an explicit height helps eliminate tiling in the transitions<br \/>\n\t\t\t\t$from<br \/>\n\t\t\t\t\t.height( screenHeight + $(window ).scrollTop() )<br \/>\n\t\t\t\t\t.addClass( name + &#8221; out&#8221; + reverseClass );<br \/>\n\t\t\t},<\/p>\n<p>\t\t\tdoneOut = function() {<\/p>\n<p>\t\t\t\tif ( $from &#038;&#038; sequential ) {<br \/>\n\t\t\t\t\tcleanFrom();<br \/>\n\t\t\t\t}<\/p>\n<p>\t\t\t\tstartIn();<br \/>\n\t\t\t},<\/p>\n<p>\t\t\tstartIn = function(){<br \/>\n\t\t\t\t$to.css(&#8220;z-index&#8221;, -10);<br \/>\n\t\t\t\t$to.addClass( $.mobile.activePageClass );\t\t\t\t<\/p>\n<p>\t\t\t\t\/\/ Send focus to page as it is now display: block<br \/>\n\t\t\t\t$.mobile.focusPage( $to );<\/p>\n<p>\t\t\t\t\/\/ Set to page height<br \/>\n\t\t\t\t$to.height( screenHeight + toScroll );<\/p>\n<p>\t\t\t\tscrollPage();<br \/>\n\t\t\t\t$to.css(&#8220;z-index&#8221;, &#8220;&#8221;);<br \/>\n\t\t\t\tif( !none ){<br \/>\n\t\t\t\t\t$to.animationComplete( doneIn );<br \/>\n\t\t\t\t}<\/p>\n<p>\t\t\t\t$to.addClass( name + &#8221; in&#8221; + reverseClass );<\/p>\n<p>\t\t\t\tif( none ){<br \/>\n\t\t\t\t\tdoneIn();<br \/>\n\t\t\t\t}<\/p>\n<p>\t\t\t},<\/p>\n<p>\t\t\tdoneIn = function() {<\/p>\n<p>\t\t\t\tif ( !sequential ) {<\/p>\n<p>\t\t\t\t\tif( $from ){<br \/>\n\t\t\t\t\t\tcleanFrom();<br \/>\n\t\t\t\t\t}<br \/>\n\t\t\t\t}<\/p>\n<p>\t\t\t\t$to<br \/>\n\t\t\t\t\t.removeClass( &#8220;out in reverse &#8221; + name )<br \/>\n\t\t\t\t\t.height( &#8220;&#8221; );<\/p>\n<p>\t\t\t\ttoggleViewportClass();<\/p>\n<p>\t\t\t\t\/\/ In some browsers (iOS5), 3D transitions block the ability to scroll to the desired location during transition<br \/>\n\t\t\t\t\/\/ This ensures we jump to that spot after the fact, if we aren&#8217;t there already.<br \/>\n\t\t\t\tif( $( window ).scrollTop() !== toScroll ){<br \/>\n\t\t\t\t\tscrollPage();<br \/>\n\t\t\t\t}<\/p>\n<p>\t\t\t\tdeferred.resolve( name, reverse, $to, $from, true );<br \/>\n\t\t\t};<\/p>\n<p>\t\ttoggleViewportClass();<\/p>\n<p>\t\tif ( $from &#038;&#038; !none ) {<br \/>\n\t\t\tstartOut();<br \/>\n\t\t}<br \/>\n\t\telse {<br \/>\n\t\t\tdoneOut();<br \/>\n\t\t}<\/p>\n<p>\t\treturn deferred.promise();<br \/>\n\t};<br \/>\n\t$.extend($.mobile, {<br \/>\n\t\tdefaultPageTransition: &#8220;slide&#8221;,<br \/>\n\t\tloadingMessage: &#8220;Loading, Please Wait&#8230;&#8221;<br \/>\n\t});<br \/>\n});[\/code]<\/p>\n<p>Now all we need to do is override all the new CSS animations with the ones from the old 1.0.1 CSS file. <\/p>\n<p>[code]@charset &#8220;utf-8&#8221;;<br \/>\n\/* CSS Document *\/<br \/>\n\/* Transitions from jQtouch (with small modifications): http:\/\/www.jqtouch.com\/<br \/>\nBuilt by David Kaneda and maintained by Jonathan Stark.<br \/>\nStripped out of jQuery Mobile 1.0.1 by Stephen &#8220;zSprawl&#8221; Russell.<br \/>\n*\/<\/p>\n<p>.in, .out {<br \/>\n\t-webkit-animation-timing-function: ease-in-out;<br \/>\n\t-webkit-animation-duration: 350ms;<br \/>\n}<\/p>\n<p>.slide.out {<br \/>\n\t-webkit-transform: translateX(-100%);<br \/>\n\t-webkit-animation-name: slideouttoleft;<br \/>\n}<\/p>\n<p>.slide.in {<br \/>\n\t-webkit-transform: translateX(0);<br \/>\n\t-webkit-animation-name: slideinfromright;<br \/>\n}<\/p>\n<p>.slide.out.reverse {<br \/>\n\t-webkit-transform: translateX(100%);<br \/>\n\t-webkit-animation-name: slideouttoright;<br \/>\n}<\/p>\n<p>.slide.in.reverse {<br \/>\n\t-webkit-transform: translateX(0);<br \/>\n\t-webkit-animation-name: slideinfromleft;<br \/>\n}<\/p>\n<p>.slideup.out {<br \/>\n\t-webkit-animation-name: dontmove;<br \/>\n\tz-index: 0;<br \/>\n}<\/p>\n<p>.slideup.in {<br \/>\n\t-webkit-transform: translateY(0);<br \/>\n\t-webkit-animation-name: slideinfrombottom;<br \/>\n\tz-index: 10;<br \/>\n}<\/p>\n<p>.slideup.in.reverse {<br \/>\n\tz-index: 0;<br \/>\n\t-webkit-animation-name: dontmove;<br \/>\n}<\/p>\n<p>.slideup.out.reverse {<br \/>\n\t-webkit-transform: translateY(100%);<br \/>\n\tz-index: 10;<br \/>\n\t-webkit-animation-name: slideouttobottom;<br \/>\n}<\/p>\n<p>.slidedown.out {<br \/>\n\t-webkit-animation-name: dontmove;<br \/>\n\tz-index: 0;<br \/>\n}<\/p>\n<p>.slidedown.in {<br \/>\n\t-webkit-transform: translateY(0);<br \/>\n\t-webkit-animation-name: slideinfromtop;<br \/>\n\tz-index: 10;<br \/>\n}<\/p>\n<p>.slidedown.in.reverse {<br \/>\n\tz-index: 0;<br \/>\n\t-webkit-animation-name: dontmove;<br \/>\n}<\/p>\n<p>.slidedown.out.reverse {<br \/>\n\t-webkit-transform: translateY(-100%);<br \/>\n\tz-index: 10;<br \/>\n\t-webkit-animation-name: slideouttotop;<br \/>\n}<\/p>\n<p>@-webkit-keyframes slideinfromright {<br \/>\n    from { -webkit-transform: translateX(100%); }<br \/>\n    to { -webkit-transform: translateX(0); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes slideinfromleft {<br \/>\n    from { -webkit-transform: translateX(-100%); }<br \/>\n    to { -webkit-transform: translateX(0); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes slideouttoleft {<br \/>\n    from { -webkit-transform: translateX(0); }<br \/>\n    to { -webkit-transform: translateX(-100%); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes slideouttoright {<br \/>\n    from { -webkit-transform: translateX(0); }<br \/>\n    to { -webkit-transform: translateX(100%); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes slideinfromtop {<br \/>\n    from { -webkit-transform: translateY(-100%); }<br \/>\n    to { -webkit-transform: translateY(0); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes slideinfrombottom {<br \/>\n    from { -webkit-transform: translateY(100%); }<br \/>\n    to { -webkit-transform: translateY(0); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes slideouttobottom {<br \/>\n    from { -webkit-transform: translateY(0); }<br \/>\n    to { -webkit-transform: translateY(100%); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes slideouttotop {<br \/>\n    from { -webkit-transform: translateY(0); }<br \/>\n    to { -webkit-transform: translateY(-100%); }<br \/>\n}<br \/>\n@-webkit-keyframes fadein {<br \/>\n    from { opacity: 0; }<br \/>\n    to { opacity: 1; }<br \/>\n}<\/p>\n<p>@-webkit-keyframes fadeout {<br \/>\n    from { opacity: 1; }<br \/>\n    to { opacity: 0; }<br \/>\n}<\/p>\n<p>.fade.out {<br \/>\n\tz-index: 0;<br \/>\n\t-webkit-animation-name: fadeout;<br \/>\n}<\/p>\n<p>.fade.in {<br \/>\n\topacity: 1;<br \/>\n\tz-index: 10;<br \/>\n\t-webkit-animation-name: fadein;<br \/>\n}<\/p>\n<p>\/* The properties in this rule are only necessary for the &#8216;flip&#8217; transition.<br \/>\n * We need specify the perspective to create a projection matrix. This will add<br \/>\n * some depth as the element flips. The depth number represents the distance of<br \/>\n * the viewer from the z-plane. According to the CSS3 spec, 1000 is a moderate<br \/>\n * value.<br \/>\n *\/<br \/>\n.viewport-flip {<br \/>\n\t-webkit-perspective: 1000;<br \/>\n\tposition: absolute;<br \/>\n}<\/p>\n<p>.ui-mobile-viewport-transitioning,<br \/>\n.ui-mobile-viewport-transitioning .ui-page {<br \/>\n\twidth: 100%;<br \/>\n\theight: 100%;<br \/>\n\toverflow: visible;<br \/>\n}<\/p>\n<p>.flip {<br \/>\n\t-webkit-animation-duration: .65s;<br \/>\n\t-webkit-backface-visibility:hidden;<br \/>\n\t-webkit-transform:translateX(0); \/* Needed to work around an iOS 3.1 bug that causes listview thumbs to disappear when -webkit-visibility:hidden is used. *\/<br \/>\n}<\/p>\n<p>.flip.out {<br \/>\n\t-webkit-transform: rotateY(-180deg) scale(.8);<br \/>\n\t-webkit-animation-name: flipouttoleft;<br \/>\n}<\/p>\n<p>.flip.in {<br \/>\n\t-webkit-transform: rotateY(0) scale(1);<br \/>\n\t-webkit-animation-name: flipinfromleft;<br \/>\n}<\/p>\n<p>\/* Shake it all about *\/<\/p>\n<p>.flip.out.reverse {<br \/>\n\t-webkit-transform: rotateY(180deg) scale(.8);<br \/>\n\t-webkit-animation-name: flipouttoright;<br \/>\n}<\/p>\n<p>.flip.in.reverse {<br \/>\n\t-webkit-transform: rotateY(0) scale(1);<br \/>\n\t-webkit-animation-name: flipinfromright;<br \/>\n}<\/p>\n<p>@-webkit-keyframes flipinfromright {<br \/>\n    from { -webkit-transform: rotateY(-180deg) scale(.8); }<br \/>\n    to { -webkit-transform: rotateY(0) scale(1); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes flipinfromleft {<br \/>\n    from { -webkit-transform: rotateY(180deg) scale(.8); }<br \/>\n    to { -webkit-transform: rotateY(0) scale(1); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes flipouttoleft {<br \/>\n    from { -webkit-transform: rotateY(0) scale(1); }<br \/>\n    to { -webkit-transform: rotateY(-180deg) scale(.8); }<br \/>\n}<\/p>\n<p>@-webkit-keyframes flipouttoright {<br \/>\n    from { -webkit-transform: rotateY(0) scale(1); }<br \/>\n    to { -webkit-transform: rotateY(180deg) scale(.8); }<br \/>\n}<\/p>\n<p>\/* Hackish, but reliable. *\/<\/p>\n<p>@-webkit-keyframes dontmove {<br \/>\n    from { opacity: 1; }<br \/>\n    to { opacity: 1; }<br \/>\n}<\/p>\n<p>.pop {<br \/>\n\t-webkit-transform-origin: 50% 50%;<br \/>\n}<\/p>\n<p>.pop.in {<br \/>\n\t-webkit-transform: scale(1);<br \/>\n    opacity: 1;<br \/>\n\t-webkit-animation-name: popin;<br \/>\n\tz-index: 10;<br \/>\n}<\/p>\n<p>.pop.in.reverse {<br \/>\n\tz-index: 0;<br \/>\n\t-webkit-animation-name: dontmove;<br \/>\n}<\/p>\n<p>.pop.out.reverse {<br \/>\n\t-webkit-transform: scale(.2);<br \/>\n\topacity: 0;<br \/>\n\t-webkit-animation-name: popout;<br \/>\n\tz-index: 10;<br \/>\n}<\/p>\n<p>@-webkit-keyframes popin {<br \/>\n    from {<br \/>\n        -webkit-transform: scale(.2);<br \/>\n        opacity: 0;<br \/>\n    }<br \/>\n    to {<br \/>\n        -webkit-transform: scale(1);<br \/>\n        opacity: 1;<br \/>\n    }<br \/>\n}<\/p>\n<p>@-webkit-keyframes popout {<br \/>\n    from {<br \/>\n        -webkit-transform: scale(1);<br \/>\n        opacity: 1;<br \/>\n    }<br \/>\n    to {<br \/>\n        -webkit-transform: scale(.2);<br \/>\n        opacity: 0;<br \/>\n    }<br \/>\n}[\/code]<\/p>\n<p>I dropped them in a file called jquery.mobile-1.0.1.transitions.css. Now include everything in the HTML header. Order matters!<\/p>\n<p>[code]<link rel=\"stylesheet\" href=\"css\/jquery.mobile-1.1.0.css\" \/>\n<link rel=\"stylesheet\" href=\"css\/jquery.mobile.1.0.1.transitions.css\" \/>\n<script type=\"text\/javascript\" charset=\"utf-8\" src=\"js\/jquery-1.7.1.min.js\"><\/script><br \/>\n<script type=\"text\/javascript\" charset=\"utf-8\" src=\"js\/utility.js\"><\/script><br \/>\n<script type=\"text\/javascript\" charset=\"utf-8\" src=\"js\/jquery.mobile-1.1.0.js\"><\/script>[\/code]<\/p>\n<p>So far I&#8217;ve tested the basic transitions. No promises that the new ones (flow\/turn) aren&#8217;t completely messed up now. YMMV.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, reverting back to the jQuery Mobile 1.0.1 transitions isn&#8217;t really &#8220;fixing&#8221; things per say but&#8230; A very hot topic in the community are the improved page transitions effects included in jQuery Mobile&#8217;s 1.1.0 release. In the previous major release 1.0.1, these page animations &#8211; slide, slideup, flip, pop &#8211; performed poorly on certain Android <a href=\"http:\/\/zsprawl.com\/iOS\/2012\/05\/fixing-the-transitions-in-jquery-mobile-1-1-0\/#more-'\" class=\"more-link\"><br \/>more \u00bb<\/a><\/p>\n","protected":false},"author":318,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,43,25],"tags":[36,120],"class_list":["post-960","post","type-post","status-publish","format-standard","hentry","category-blog","category-css","category-jquery-mobile","tag-css3","tag-jquery-mobile"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts\/960"}],"collection":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/users\/318"}],"replies":[{"embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/comments?post=960"}],"version-history":[{"count":8,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts\/960\/revisions"}],"predecessor-version":[{"id":1145,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts\/960\/revisions\/1145"}],"wp:attachment":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/media?parent=960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/categories?post=960"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/tags?post=960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}