var base = box.clientHeight;
// If no default is given, find the native size.
// TODO: find a better way! This makes an annoying flicker!
if ( findNative ) {
box.style.height = "";
toHeight = box.clientHeight;
box.style.height = base;
}
🔒 Locked
[web] DHTML: finding natural size of an object
Advertisement
Original Post
I'm writing some animation tweens for a DHTML/AJAX framework I'm developing, and I've hit a small brick wall. I want to determine the 'natural size' of an element, usually a DIV. Why: I've made a zero-height (and zero-opacity) DIV where some content will eventually appear. The AJAX engine then puts some content in it, but because of the current {overflow:hide; height:0px;} directives, it remains hidden. I now want to animate a sort of 'fold-out' by growing the DIV out to the size it would have been without the height:0px; directive. Currently, I do this with the following javascript... So: does anyone know a way to eliminate the flicker that this causes (because of the update-and-restore), or another way to determine content size? The only way I can think of is to put another DIV inside this one, and let its size guide me, but this seems just as much a hack as my current method. Anyone else solved this problem?
Well, it was worth a shot. Setting to 100% in IE and Firefox I get a box the height of the window, and setting height to 0 (any unit) in IE or Opera makes them act like I never specified a height (they pop back out to natural size).
Any suggestions for either problem? I'm mostly concerned with the annoying pop-back; setting {display:none;} or {display:hidden;} has no effect in making the element remove itself from the layout engine in IE; it's invisible but it still takes up room (as correct for 'hidden', but not for 'none', curse it).
Any suggestions for either problem? I'm mostly concerned with the annoying pop-back; setting {display:none;} or {display:hidden;} has no effect in making the element remove itself from the layout engine in IE; it's invisible but it still takes up room (as correct for 'hidden', but not for 'none', curse it).
Sample setup on my server (please don't hit my bandwidth too hard)...
http://moonshot.no-ip.org/framework/
Try it in whatever browsers you've got. In Firefox Linux, everything works perfect. In Firefox Windows, everything except "Native" size works (I end up with the blue box being as tall as the window), and in IE Windows, everything but 0px and Native sizes work (same bug). In other browsers, I get various combinations of the above bugs.
http://moonshot.no-ip.org/framework/
Try it in whatever browsers you've got. In Firefox Linux, everything works perfect. In Firefox Windows, everything except "Native" size works (I end up with the blue box being as tall as the window), and in IE Windows, everything but 0px and Native sizes work (same bug). In other browsers, I get various combinations of the above bugs.
You can hide the div with the items (target) in another div (bigger), set the bigger div invisible, and the pop up the target to its natural size with auto.
You can now get the value, set target height to 0, show the bigger div, set its height to the value + a few pixels, and make the target div grow gradually to the value.
edit: oh, you mentioned this in the last line. uh well, try using DOM explorer in firefox. There might just be a property for this. I worked with a javascript that was shrinking images, and i needed the natural size of the image, and i found it this way. They were naturalWidth and naturalHeight.
You can now get the value, set target height to 0, show the bigger div, set its height to the value + a few pixels, and make the target div grow gradually to the value.
edit: oh, you mentioned this in the last line. uh well, try using DOM explorer in firefox. There might just be a property for this. I worked with a javascript that was shrinking images, and i needed the natural size of the image, and i found it this way. They were naturalWidth and naturalHeight.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement