kamesh
kamesh

Reputation: 2424

jquery mobile pageContainer to load external page with transition effects

I am currently working on mobile application using jquery mobile v1.4.2 . . . . Almost all the functionality was done. now I want to add transition effects for all the pages ...

Question : In jquery mobile v1.4.2 (doc) tells to use pageContainer instead of pagechange and pageload and I don't know how to load external page(another HTML file) with transition effect.I didn't find must example in google and any reference links is appreciated .

Thanks in advance

Upvotes: 0

Views: 4740

Answers (1)

Gajotres
Gajotres

Reputation: 57309

  1. You can easily force default transition with this code:

    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script>
        $(document).bind("mobileinit", function () {
            $.mobile.defaultPageTransition = 'slide';
        });
    </script>
    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>   
    

    Don't forget one thing, mobileinit event must be initialized BEFORE jQuery Mobile, just like in my example.

  2. Regarding your second question, you will do it like this:

    $( ":mobile-pagecontainer" ).pagecontainer( "load", "second.html", { role: "page" } );
    

    Example:

    index.html

    <!DOCTYPE html>
    <html>
        <head>
            <title>jQM Complex Demo</title>
            <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
            <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
            <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" /> 
            <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
            <script>
                $(document).bind("mobileinit", function(){
                    $.mobile.defaultPageTransition = "slide";
                });            
            </script>
            <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
            <script>
                $(document).on('pagecreate', '#index', function(){ 
                    $( ":mobile-pagecontainer" ).pagecontainer( "load", "second.html", { role: "page" } );
                });     
    
            </script>       
        </head>
        <body>     
            <div data-role="page" id="index" data-theme="a" >
                <div data-role="header">
                    <h3>
                        First Page
                    </h3>
                    <a href="#second" class="ui-btn-right">Next</a>
                </div>
    
                <div data-role="content">
    
                </div>
    
                <div data-role="footer" data-position="fixed">
    
                </div>
            </div>  
        </body>
    </html>   
    

    second.html

    <div data-role="page" id="second" data-theme="a" >
        <div data-role="header">
            <h3>
                Second Page
            </h3>
            <a href="#index" class="ui-btn-left">Back</a>
        </div>
    
        <div data-role="content">
    
        </div>
    
        <div data-role="footer" data-position="fixed">
    
        </div>
    </div> 
    

Upvotes: 5

Related Questions