Swipe in the middle to open panel with jQuery Mobile?

拜拜、爱过 提交于 2019-12-10 12:16:17

问题


I have a small bars button in my nav header that opens the panel when clicked, but how do I make it so that when I swipe to the right from the middle of the app, it opens the left panel? You can see this on many native apps including Facebook. Thanks for any help!


回答1:


I think this is what you'll want (you may want to refine your selector for your swipe area) -

$('body').on('swiperight', function () {
    $('#defaultpanel').panel('open', '');
});

$('body').on('swipeleft', function () {
    $('#defaultpanel').panel('close');
});

jsFiddle Demo




回答2:


Listen to swipe events swipeleft and swiperight and accordingly, open panels $('#id').panel('open').

Demo

$(document).on('swipeleft swiperight', function (e) {
  if (e.type == 'swiperight') {
    $('#left').panel('open');
  }
  if (e.type == 'swipeleft') {
    $('#right').panel('open');
  }
});



回答3:


$( 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" );
            }
        }
    }); });

here is the documentation: http://view.jquerymobile.com/1.3.0/docs/examples/panels/panel-swipe-open.php#&ui-state=dialog



来源:https://stackoverflow.com/questions/17535768/swipe-in-the-middle-to-open-panel-with-jquery-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!