Fixing flickers of jquerymobile page slide transition

原文:http://outof.me/fixing-flickers-jumps-of-jquery-mobile-transitions-in-phonegap-apps/

Ok, so what worked for me was instead of using a body tag as a page container I used an absolutely positioned div inside of a body

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
    <title>jQuery Mobile transitions flickers & jumps workaround</title>
    <meta charset="utf-8">
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="scripts/libs/jquery.mobile/jquery.mobile-1.1.0.css"/>
    <style type="text/css">
        body {
            /* Setting body margins to 0 to have proper positioning of #container div */
            margin: 0;
        }
            /* #container div with absolute position and 100% width and height so it takes up whole window */
        #container {
            position: absolute;
            width: 100%;
            height: 100%;
        }
    </style>
    <script type="text/javascript" src="scripts/libs/jquery/jquery-1.7.1.js"></script>
    <script type="text/javascript">
        $(document).one("mobileinit", function () {
            // Setting #container div as a jqm pageContainer
            $.mobile.pageContainer = $('#container');
            // Setting default page transition to slide
            $.mobile.defaultPageTransition = 'slide';
        });
    </script>
    <script type="text/javascript" src="scripts/libs/jquery.mobile/jquery.mobile-1.1.0.js"></script>
</head>
<body>
    <!-- jqm pages container -->
    <div id="container"/>
</body>
</html>