jquery - $ ('body' ).css ('overflow-y' , 'auto' ) 在 Internet Explorer 上不工作

标签 jquery css

我正在尝试根据窗口高度设置不同的浏览器行为。 我想要的是 如果用户在上网本上,我的脚本只会将 css overflow-y 激活为“自动”,因此如果内容大于屏幕,用户可以看到所有内容。 如果用户在大屏幕上,我想 overflow hidden 并让我的主 div 溢出 = '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');
    }
}

最佳答案

$('html, body').css('overflowY', 'auto'); 

解决了这个问题。

关于jquery - $ ('body' ).css ('overflow-y' , 'auto' ) 在 Internet Explorer 上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5772373/

相关文章:

jQuery div slider 防止滑动时点击

javascript - 从 Farbtastic 获取十六进制值并转换为 RGB 以在 php 中的 imagefilter 中使用

php - 使用 PHP 从显示 : none to display: block 设置一个 CSS ID

css - 使用正确的本地字体名称

html - 如何垂直对齐 ul 内的按钮?

php - 如何通过Ajax发送php变量仅当它不为空时

javascript - 类型错误 : "Not a function" using "this" keyword in a function

jquery - ajax返回成功时改变div的css

javascript - 如何拖动内容并调整其大小Editable ="true"div

javascript - 如何在 JavaScript 中使用媒体查询