我正在尝试根据窗口高度的不同而有不同的浏览器行为。我想要的是,如果用户是在上网本上,我的脚本只会激活css溢出-y到‘自动’,因此,如果内容大于屏幕,用户可以看到一切。如果用户在一个大屏幕上,我想要有溢出隐藏,只有我的主要div与overflow = 'auto',这样页脚可以在屏幕底部,但内容也可以被浏览,如果比屏幕大。
发布基本代码后,它可以在mac的大屏幕上运行,但在internet explorer上不能,无论是大屏幕还是小屏幕……
该怎么办呢?
提前感谢您的帮助
CSS
html, body {
min-width: 600px;
margin: 0;
padding: 0;
overflow: hidden;
}
#header {
position:relative; /* IE7 overflow bug */
clear:both;
float:left;
width:100%;
height: 200px;
overflow: hidden;
}
#main {
position:relative; /* IE7 overflow bug */
clear:both;
float:left;
width:100%;
overflow-x: hidden;
}
#footer {
position:relative; /* IE7 overflow bug */
clear:both;
float:left;
width:100%;
height: 100px;
overflow: hidden;
}
jQuery
if( typeof( window.innerWidth ) == 'number' ) {
// No-IE
var screen_height = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6 +
var screen_height = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4
var screen_height = document.body.clientHeight;
}
var header_height = $('#header').height();
var footer_height = $('#footer').height();
var main_height = screen_height - header_height - footer_height;
//
if (navigator.userAgent.toLowerCase().search("iphone") > -1 || navigator.userAgent.toLowerCase().search("ipod") > -1) {
$('body').css('overflow-y', 'auto');
} else {
if(screen_height > 550) {
$('#main').css('height', main_height + 'px');
$('#main').css('overflow-y', 'auto');
} else {
$('html, body').css('overflow-y', 'auto');
}
}
https://stackoverflow.com/questions/5772373
复制相似问题