1

我对 js 和 jqm 很陌生。所以我有一个基本脚本,当我滚动侧面时会打开一个面板。我在所有页面上都使用#panel,但是该脚本仅适用于第一页。什么是让这个工作永远页面的最佳方法?我必须在每页的末尾包含它吗?我应该单独命名每个面板并执行 ("#panel, #panel2") 等吗?

<script>
$( document ).on( "pageinit", document, function() {
    $( document ).on( "swipeleft", document, function( e ) {

        if ( $.mobile.activePage.jqmData( "panel" ) !== "open" ) {
            if ( e.type === "swipeleft"  ) {
               $( "#mypanel" ).panel( "open" );
            }
        }
    });
});    
</script>
4

2 回答 2

0

我认为您应该尝试一下:

$( document ).on( "swipeleft", $.mobile.activePage, function( e )
于 2013-08-08T09:06:19.390 回答
0

如果您对所有页面$.mobile.activePage.find('#id').panel('open')使用相同的面板ID ,则应该使用。此外,您应该将面板添加到每个页面。

演示

$(document).on("swipeleft", '[data-role=page]', function (e) {
  if (!$.mobile.activePage.hasClass('ui-page-panel-open') && e.type == "swipeleft") {
    $.mobile.activePage.find("#panel").panel("open");
  }
});
于 2013-08-08T10:50:16.413 回答