I would like to do a jquery function that when window resize, it search div with css-class name "taskbox" and set the max-height to the parent div height - current offset for the taskbox to be able to be smaller than the available space but do not extend it.
+2
A:
You might try looking for an existing solution (jQuery has an immense plug-in community):
At the very least this will get you started.
thenduks
2009-02-20 17:26:42
I found this answer too with googling, its too bad its not even close to what the questioner is asking for...
jfar
2009-03-11 01:38:49
How is this not close? Look at the code for that plugin and you'll notice that it's got code that normalizes the height of divs. Enough to get started, as I said.
thenduks
2009-03-11 02:59:37
The question was about setting a height relative to the browser window height, you posted about a script that sets heights, missing a key part of the problem. "Enough to get you started" isn't an answer and shouldn't be worth any points.
jfar
2009-03-11 15:27:52
Lucky for me, then, that you aren't 'the decider' on what deserves points. Not that I'm especially attached to 'points'... I don't really care. To prove it, I'll mod myself down, just for you. I yield to your superior answer to this question... oh wait, you didn't write one.
thenduks
2009-03-11 19:33:48
Oh right, turns out you can't mod your own answer down. Ah well, my point is made.
thenduks
2009-03-11 19:35:00
I was typing it out when Adam's answer came in, in fact I was actually testing it in a browser because I'm not that good with jQuery yet. You made no points that matter. The questioner knew he could set a height with jQuery, he just need to know how to tie that in with a browser window.
jfar
2009-03-14 15:31:38
And this is a big deal for you because...? Get back to work, man.
thenduks
2009-03-15 14:32:34
+3
A:
I'm not certain exactly what you're trying to do, but to get all the elements that contain an element that has the taskbox class you can use:
$(":has(.taskbox)").height(300);
This will adjust the height of all those elements. To adjust the height of all the taskboxes based on the height of the parent element on window resize you can do something like this:
$(window).resize(function() {
var parent = $(".taskbox");
$(".taskbox").each(function() {
$(this).height($(this).parent().height() - 50);
});
});
Keep in mind that the parent elements will need to have height specified in order for this to work well. You can get the height of the window with:
$(window).height();
Adam
2009-02-20 23:11:35