的其他解決方案只能如果你想上的頁面加載和頁面大小或方向變化適用於移動解決方案在頁面加載工作一次。使用這一個。
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'; });
}
});
請檢查我的答案。如果你需要更多的信息,請告訴我:) –