如果您想要一个适用于页面加载和页面调整大小或移动方向更改的解决方案,其他解决方案仅在页面加载时工作一次。使用这个。
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'; });
}
});