【问题标题】:jquery mobile Panel Swipe function causing errorsjquery mobile Panel Swipe功能导致错误
【发布时间】:2013-02-19 21:03:44
【问题描述】:

我很难过,我有一个使用 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 移动用户!

【问题讨论】:

    标签: jquery jquery-mobile initialization panel swipe


    【解决方案1】:

    如果是这个消息:

    "无法在初始化之前调用面板上的方法;试图 调用方法'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" );           
            }        
        });
    });
    

    【讨论】:

    • 感谢您的帮助,这是我所做的if ( $j.mobile.activePage.jqmData( "panel" ) !== "open" ) { if ( e.type === "swipeleft" ) { $j( "#right-panel" ).panel().panel( "open" ); } else if ( e.type === "swiperight" ) { $j( "#left-panel" ).panel().panel("open"); } } 现在我得到 _Cannot read property 'nodeType' of undefined _ 以及这个 _Uncaught TypeError: Cannot call method 'jqmData' of null _
    • 你是一个救生员! puno hvala ja sam iz velka kladusa bosna ali sam doso u ameriku kad sam imo 6 godina,nista vidimo se ZIVI!
    • Nema problema, ako budeš trebao dodatnu pomoć javi mi se na mail direktno.
    猜你喜欢
    • 2014-08-21
    • 1970-01-01
    • 2020-02-17
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 2016-09-07
    • 2017-08-27
    • 1970-01-01
    相关资源
    最近更新 更多