jquery mobile面板滑动功能导致错误

标签 jquery jquery-mobile initialization panel swipe

我遇到了这样的困难,我有一个使用 mootools 的翻转时钟,然后是一个使用 Yahoo API 的天气小部件,现在我不知道是什么原因造成的

"cannot call methods on panel prior to initialization; attempted to call method '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 mobile 用户!

最佳答案

如果是此消息:

"cannot call methods on panel prior to initialization; attempted to call method '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" );           
        }        
    });
});

关于jquery mobile面板滑动功能导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14967382/

相关文章:

ajax - 在启动时加载所有页面 jQueryMobile

jquery-mobile - 区分桌面用户和移动用户的方法

objective-c - 重新初始化对象

java - 在循环内声明一个变量更有效,还是仅仅重新分配它更有效?

javascript - ajax方法帖子错误

javascript - 为什么这个普通的 JavaScript 可以工作,而它等效的 jQuery 会失败?

jQuery 和位置 :relative messing my hover up! 为什么?

javascript - 将 cURL 转换为 jQuery AJAX

c# - jQuery Mobile + MVC 3 + Request.Path

objective-c - 为什么我需要将 self 转换为 id?