Jul
14
2011

Eliminating annoying flicker transitions with jQuery Mobile on Android

I’ve been using PhoneGap along with jQuery Mobile to do some protoyping work for a client on a range of mobile devices.  When testing on Android 2.2 (HTC Desire in my case), I noticed a nasty flicker on the CSS swipe transition. Seems others have seen this too. On my device it seems to occur once at the start of the transition, and once at the end.

Anyways, after much googling, the stackoverflow magic that fixes it seems to be to do with the -webkit-backface-visibility tag. After I added the magic CSS to my jQuery Mobile page tags life was flicker-free again. Here’s the magic sauce I had to add to my CSS when using PhoneGap 0.9.6 and jQuery Mobile 1.0 beta 1:

.ui-page {
    -webkit-backface-visibility: hidden;
}

And say goodnight to the dreaded Android flicker!

About the Author: Glen Smith

34 Comments + Add Comment

  • Thank you sir!

  • Amazing! A week of frustration with my android/phonegap web app solved! Thanks!

  • Cheers Glen!

    I had the same issue on a phonegap / jquerymobile / iOS project. Fixed the damn issue.

  • Hm, where exactly did you put that…?

    • @CW, you need to put it in a css file that loads after the jquerymobile.css file.

      • OK, thx.
        Then it just doesn’t work for me… :(

  • Whoa.. Seriously just saved my project!! Now if I can only stop the flicker of the fixed position nav bar…

    Thanks!

  • Problem with this workaround though, is that if you use the Android native select dropdowns (i.e. add the data-role=”none” attribute to them), they are no longer selectable.

    I believe it is because of the way Android natively shows select dropdowns in a little pop up thing.

    • We experienced this problem as well. It made our forms generally unusable.
      Transition flickers were comparatively minor in effect

  • Thanks … its a life saver

  • Doesn’t work!

    I created an android project in eclipse. Just a few blank html file sin the assets/www pointing to eachother, and I’m not using jQuery yet.
    Still the black transition appears.

    Can anyone tell how this is solved, because I’ve seen that this is an issue since beginning of 2011 already.
    The link to the workaround https://github.com/phonegap/phonegap-android/commit/361a7aacc5ed1257e11d0c676a940188b7e7922d
    is frankly quit unclear as to what to do with it. SPecially if you’re new to Phonegap.

  • works like a charm! Thanks a lot the bug was driving me crazy.

  • Thnx! Works like a charm =)

  • Beautiful sir! Give that man a cookie!

  • Isnt everybody got the problem with the Select menus while we use this solution? I am facing it….. Select menus are not at all working..
    In addition at the place I used auto complete in a input field.. there it boules the page while typing

  • Doesn’t work in Android 2.3 (after upgrade from 2.2) on Samsung Galaxy Tab – very much of flickering – not usable. Fix makes also select menus unusable.

  • working fine.. but its effecting my input text field when am using this code. can anyone resolve that problem with out effecting the input text field.

  • This work for me (whit some adjustments) because this property makes my input and select fields unusable.

    So, my solution was something like:

    in my case, inside the touchstart method i put something like this:

    var page = $(“#somepage”);
    page.css(“-webkit-backface-visibility”,”hidden”);
    $.mobile.changePage(“#somepage”, {transition: “slide”});
    setTimeout(function () {
    page.css(“-webkit-backface-visibility”,”visible”); }, 500);

    Works great. tks

    • · By ‘the touchstart method’, do you mean inside the ‘function handleTouchStart( event ) ‘ – body inside jquery.mobile-1.01.min.js?
      · If i have many pages (divs with data-role=”page”..), what to put insted of ‘#somepage’ ?
      I am new to this, so pleas have mercy on me. Thanks.

  • Thanks a million for sharing it!!!

  • doesn’t works for me,,, it does fix the flicker transition, but still the select boxes are frozen…. this si so frustrating,,, everything works like a charm in iPhone…

  • Great! Fixed my iOS5 flickering headache

  • Fixed a few problems, but still some flickering though. But still thx :D

  • Thank you sir.You are genious.Great job, was thinking that my function was getting called twice, turned out to be a css issue.

  • Didn’t work for me iOS. Still had the white screen flickering everytime I navigated to another page with a transition.

    I changed the background value for .ui-mobile and .ui-mobile-viewport to the exact same value as I set for the background of .ui-page .. The white flash is gone now.

  • I’m experiencing that flicker with an iPad 2/iOS 5.1, jQuery Mobile 1.1.0-RC1, PhoneGap 1.4 and this fixed it. Thank you!

  • Thanks a lot!

  • Its great the flickering is out, but now one more issue is appearing specially with the pages with input field. In HTC, a new Text box is appearing on top of the existing text box and on typing the input box is start jumping. Do you guys have any fix for this (of course with using -webkit-backface-visibility: hidden; )

    Thanks.

  • Awesome, this fixed the same issue using a homescreen webapp built with jQuery Mobile.

    Thanks

  • Awesome ! with your help I fixed the issue for blackberry app ! thanks. !

  • It works for iOS too.
    You saved my day. Thanks a lot.

  • still facing same problem after use same code after jquery.css file
    .ui-page {
    -webkit-backface-visibility: hidden;
    }

    please help ,its so frustrating moment for me.

  • That’s PERFECT!! Thank you so much!! After googling and googling I never found a solution until today that I found this while I was searching other things not related XD

    Did you inform to jquery mobile team?? This should be included in the next release!!

  • I know someone already asked this question but exactly where does the piece of code go for this ? In one of the jquery css files in my main css file???
    Thanks

Leave a comment

Glen Smith

About Glen

Co-author Grails in Action