Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$('body').css('overflow-y', 'auto') doesn't work on Internet explorer

Tags:

I'm trying to have diferent browser behaviours depending on window height. What I want is if user is on a netbook my script will just activate the css overflow-y to 'auto' so if content is bigger than screen user can see everything. if user is in a big screen, I want to have overflow hidden and just have my main div with overflow = 'auto', so the footer can be at bottom of screen, but content can also be viwed if bigger than screen.

posting the basic code for this, it works on big screens on mac, but on internet explorer it doesn't, either on big or small screens...

what to do?

Thanks for help in advance

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');     } } 
like image 887
Pluda Avatar asked Apr 24 '11 18:04

Pluda


People also ask

Why overflow is not working in CSS?

One of the most common causes of overflow is fixed-width elements. Generally speaking, don't fix the width of any element that should work at multiple viewport sizes.

How do I fix the overflow in CSS?

The content renders outside the element's box. hidden - The overflow is clipped, and the rest of the content will be invisible. scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content. auto - Similar to scroll , but it adds scrollbars only when necessary.

What is overflow-y in CSS?

The overflow-y property specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the top and bottom edges.

What does overflow auto do in CSS?

The "overflow" property controls content that breaks outside of its boundaries. So the "auto" value ensures that when the content proceeds outside of its box the content gets hidden whilst a scroll bar becomes visible for users to read the rest of the content.


2 Answers

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

solves this problem.

like image 166
Pluda Avatar answered Oct 03 '22 14:10

Pluda


Try setting it with overflowY:

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

Dashes in attribute names typically don't work when set with JavaScript, especially in IE.

Hope that works.

like image 29
clmarquart Avatar answered Oct 03 '22 13:10

clmarquart