首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >$('body').css('overflow-y','auto')在‘t上不起作用

$('body').css('overflow-y','auto')在‘t上不起作用
EN

Stack Overflow用户
提问于 2011-04-25 02:26:59
回答 2查看 83.8K关注 0票数 22

我正在尝试根据窗口高度的不同而有不同的浏览器行为。我想要的是,如果用户是在上网本上,我的脚本只会激活css溢出-y到‘自动’,因此,如果内容大于屏幕,用户可以看到一切。如果用户在一个大屏幕上,我想要有溢出隐藏,只有我的主要div与overflow = 'auto',这样页脚可以在屏幕底部,但内容也可以被浏览,如果比屏幕大。

发布基本代码后,它可以在mac的大屏幕上运行,但在internet explorer上不能,无论是大屏幕还是小屏幕……

该怎么办呢?

提前感谢您的帮助

CSS

代码语言:javascript
复制
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

代码语言:javascript
复制
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');
    }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5772373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档