我试图根据窗口高度有不同的浏览器行为.我想要的是如果用户在上网本上我的脚本只会激活css overflow-y为'auto',所以如果内容大于屏幕,用户可以看到所有内容.如果用户在一个大屏幕上,我想隐藏溢出,只需要我的主div与overflow ='auto',所以页脚可以在屏幕的底部,但内容也可以是viwed,如果大于屏幕.
发布这个的基本代码,它适用于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;
}
Run Code Online (Sandbox Code Playgroud)
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');
}
}
Run Code Online (Sandbox Code Playgroud)
Plu*_*uda 39
$('html, body').css('overflowY', 'auto');
Run Code Online (Sandbox Code Playgroud)
解决了这个问题.
尝试设置overflowY:
$('body').css('overflowY', 'auto');
Run Code Online (Sandbox Code Playgroud)
使用JavaScript设置时,属性名称中的破折号通常不起作用,尤其是在IE中.
希望有效.
| 归档时间: |
|
| 查看次数: |
76696 次 |
| 最近记录: |