如果您手动设置类,您可以做到最好,但为了将来改进 JQM,也许您现在可以同时做这两个:
我刚刚改进了Gajotres的答案并导致了jsFiddle
var panel = $("#rightpanel"),
DEFAULT = {
POSITION: {
left: {type: "left"},
right: {type: "right"}
},
DISPLAY: {
overlay: { type: "overlay" , className: "ui-panel-display-overlay"},
reveal: { type: "reveal" , className: "ui-panel-display-reveal"},
push: { type: "push" , className: "ui-panel-display-push"}
}
},
lastState = {
display: DEFAULT.DISPLAY.push,
position: DEFAULT.POSITION.left
};
function options (key, value) {
return panel.panel("option", key, value);
}
function position (pos) {
// { left | right }
if (
DEFAULT.POSITION[pos] &&
DEFAULT.POSITION[pos].type !== lastState.position.type
){
panel.panel("close");
lastState.position = DEFAULT.POSITION[pos]
panel
.toggleClass("ui-panel-position-left ui-panel-position-right");
return options("position", pos);
}
}
function display (disp) {
// { overlay | reveal | push }
if (
DEFAULT.DISPLAY[disp] &&
DEFAULT.DISPLAY[disp].type !== lastState.display.type
) {
panel.panel("close");
lastState.display = DEFAULT.DISPLAY[disp]
panel
.removeClass("ui-panel-display-reveal ui-panel-display-overlay ui-panel-display-push")
.addClass(display.className);
return options("display", disp);
}
}
$(document).on('pagebeforeshow', '#index', function(){
$(document).on('click', '#openpanel', function() {
position("right");
panel.panel("open")
});
});