我遇到了这样的困难,我有一个使用 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/