的其他解决方案只能如果你想上的页面加载和页面大小或方向变化适用于移动解决方案在页面加载工作一次。使用这一个。
var state = 'undefined';
$('#responsive-menu-button').sidr({
name: 'sidr-main',
source: '#navigation'
});
$('#responsive-menu-button').off('click').click(function(e){
e.preventDefault();
if(state == 'close'){
$.sidr('open','sidr-main', function(){ state = 'open'; });
} else {
$.sidr('close','sidr-main', function(){ state = 'close'; });
}
});
var deviceWidth = $(window).width();
var breakWidth = 480;
if(state == 'undefined'){
if(deviceWidth <= breakWidth) {
state = 'close';
} else {
setTimeout(function(){
$.sidr('open','sidr-main', function(){ state = 'open'; });
}, 100);
}
}
$(window).off('resize').bind('resize', function() {
deviceWidth = $(window).width();
if(deviceWidth > breakWidth && state == 'close') {
$.sidr('open','sidr-main', function(){ state = 'open'; });
}
if(deviceWidth <= breakWidth && state == 'open') {
$.sidr('close','sidr-main', function(){ state = 'close'; });
}
});
请检查我的答案。如果你需要更多的信息,请告诉我:) –