The goal is to have a page with two panels (left-panel, right-panel) that open and close on swipe events, but also enable a responsive design (such that when the screen is large enough, the user can keep 1 panel open while using the page-contents).
I found good examples on the JQM sites: .3.1/dist/demos/examples/panels/panel-swipe-open.html .3.1/dist/demos/widgets/panels/ (section on making the panel responsive)
I got really close. On a small screen, I can swipe open/close perfectly. On a large screen (where the panel is held and content is responsive), I can only swipe to close on the panel itself. If I swipe on the page contents, nothing happens. Testing the following code, I see that the swipe event is being called.
$( document ).on("swipeleft swiperight", "#index", function( e ) {
console.log('swiped!!')
// 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" );
}
}
});
I have also been looking at the css code:
.ui-responsive-panel .ui-panel-dismiss-display-reveal {
display: none;
}
(If I ment out display, it wont let me use the page contents on a large screen).
The goal is to have a page with two panels (left-panel, right-panel) that open and close on swipe events, but also enable a responsive design (such that when the screen is large enough, the user can keep 1 panel open while using the page-contents).
I found good examples on the JQM sites: http://view.jquerymobile./1.3.1/dist/demos/examples/panels/panel-swipe-open.html http://view.jquerymobile./1.3.1/dist/demos/widgets/panels/ (section on making the panel responsive)
I got really close. On a small screen, I can swipe open/close perfectly. On a large screen (where the panel is held and content is responsive), I can only swipe to close on the panel itself. If I swipe on the page contents, nothing happens. Testing the following code, I see that the swipe event is being called.
$( document ).on("swipeleft swiperight", "#index", function( e ) {
console.log('swiped!!')
// 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" );
}
}
});
I have also been looking at the css code:
.ui-responsive-panel .ui-panel-dismiss-display-reveal {
display: none;
}
(If I ment out display, it wont let me use the page contents on a large screen).
Share Improve this question asked May 22, 2013 at 23:05 FedericoFederico 6,4786 gold badges37 silver badges43 bronze badges1 Answer
Reset to default 3I figured the easiest way to fix this problem was to force close any open panels. After hours of searching, I just thought a little bit and came up with this modification:
$( document ).on("swipeleft swiperight", "#ticket", function( e ) {
console.log('swiped!!')
// 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" );
}
}
else if ($.mobile.activePage.jqmData( "panel" ) == "open"){
$( "#left-panel" ).panel( "close" );
$( "#right-panel" ).panel( "close" );
}
});
All it does is close any panels on a swipe event if they are open.
Another tip about responsive panels -- make sure you are using the css class that corresponds to your panel option.
If you use reveal
, the class is .ui-panel-dismiss-display-reveal
If you use push
, the class is .ui-panel-dismiss-display-push
Hope this helps someone out!