简体   繁体   中英

jQuery Mobile, open dialog

I have a problem to open with transitions jQuery Mobile.

I can not create a transition effect.

Here is my code...

    <div id="main" data-role="content" data-theme="d">
<a href="#dialog" data-role="button" data-rel="dialog" data-transition="fade" data-inline="true">dialog</a>
<!-- ... -->
<div data-role="page" id="dialog"><!-- dialog-->
    <div data-role="header" data-theme="e">
        <h1>Foo</h1>
        </div>
    <div data-role="content" data-theme="e">
        <p>Bar</p>
    </div>
</div>
<!-- Footer -->
jQuery('#page').live('pageinit', function() {
    $('.widget ul').attr('data-inset', 'true').attr('data-theme', 'd').attr('data-dividertheme', 'b').attr('data-role', 'listview');
    $('.widget ul').listview();
});
jQuery('#page').live('changepage', function() {
$('#dialog', 'pop', true, true);
});

Thanks for your help.

Regards,

V.

On the data-role="page" element, you need to add data-rel="dialog", instead of "id" to get the page to appear as a dialog.

See here: http://jquerymobile.com/test/docs/pages/page-dialogs.html

jQuery(document).delegate('#page', 'pageinit', function() {
    $('.widget ul').attr('data-inset', 'true').attr('data-theme', 'd').attr('data-dividertheme', 'b').attr('data-role', 'listview').listview();
}).delegate('#page', 'changepage', function() {
    $.mobile.changePage('#dialog', {
        transition : 'pop',
        role       : 'dialog'//this means you don't have to declare `data-role="dialog"` on the page if you don't want to
    });
});

Notice I chained the .listview() function call and the second .delegate() function call. I also changed out the .live() for .delegate() since as of jQuery 1.7, .live() is depreciated. To navigate to a page you use $.mobile.changePage() : http://jquerymobile.com/demos/1.1.0-rc.1/docs/api/methods.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM