jquery mobile Panel滑动功能导致错误

时间:2013-02-19 21:03:44

标签: jquery jquery-mobile initialization panel swipe

我有这么难的时候,我有一个使用mootools的翻转时钟,然后是使用Yahoo API的天气小部件,现在我不知道是什么原因导致

  

“无法在初始化之前调用面板上的方法;尝试了   调用方法'open'“

所以我跟着这个演示,http://view.jquerymobile.com/master/docs/examples/panels/panel-swipe-open.php#demo-page,现在我收到了错误。

$( document ).on( "pageinit", "#demo-page", function() {
$( document ).on( "swipeleft swiperight", "#demo-page", function( e ) {
    // We check if there is no open panel on the page because otherwise
    // a swipe to close the left panel would also open the right panel (and v.v.).
    // We do this by checking the data that the framework stores on the page element (panel: open).
    if ( $.mobile.activePage.jqmData( "panel" ) !== "open" ) {
        if ( e.type === "swipeleft"  ) {
            $( "#right-panel" ).panel( "open" );
        } else if ( e.type === "swiperight" ) {
            $( "#left-panel" ).panel( "open" );
        }
    }
});

});

我有点死胡同,因为我有它工作,随时查看我的代码,http://yaasko.com/gra423/project-4.3/如果你试图向左或向右滑动,控制台将输出错误。

如果您能提供帮助,请告诉我,第一次jquery移动用户!

1 个答案:

答案 0 :(得分:10)

如果是这个消息:

  

“无法在初始化之前调用面板上的方法;尝试了   调用方法'open'“

像这样打开面板:

$( "#left-panel" ).panel().panel("open");

第一个panel()调用将初始化它,第二个将打开它。

编辑:

$(document).on('pagebeforeshow', '#index', function(){        
    $( document ).on( "swipeleft swiperight", "#index", function( e ) {
        if ($.mobile.activePage.find('#left-panel').hasClass('ui-panel-closed') && e.type === "swipeleft") {
            $( "#right-panel" ).panel( "open" ); 
        }    

        if ($.mobile.activePage.find('#right-panel').hasClass('ui-panel-closed') &&  e.type === "swiperight") {
            $( "#left-panel" ).panel( "open" );           
        }        
    });
});
相关问题