Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  89] [ 3]  / answers: 1 / hits: 15448  / 14 Years ago, thu, december 30, 2010, 12:00:00

A view in my web app has a table which may be extremely long, so I wrapped it in a div with overflow: auto; max-height: 400px; so users can scroll through it while keeping the other controls on the page visible.



I want to use a bit of JavaScript to dynamically adjust the max-height CSS property so the div stretches to the bottom of the browser window. How can I determine this value? jQuery solutions are fine.



The table doesn't start at the top of the page, so I can't just set the height to 100%.


More From » jquery

 Answers
18

Something like this would work I think:



var topOfDiv = $('#divID').offset().top;
var bottomOfVisibleWindow = $(window).height();
$('#divID').css('max-height', bottomOfVisibleWindow - topOfDiv - 100);

[#94436] Tuesday, December 28, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brendan

Total Points: 426
Total Questions: 110
Total Answers: 94

Location: Western Sahara
Member since Mon, May 3, 2021
3 Years ago
;