473,395 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Ascertain needed div height to fit content?

I have a javascript that manipulates the DOM with content that will be
of variable heights. How can I ascertain how high my div needs to be in
order to show all content without scroll bars. Rather than just having
this happen automatically, I want the div to expand with a DHTML
animation. So, I need to know where to tell the script to stop
expanding. In pseudo-code:

function divAni(){
if(this.height > 0){
if(this.height > 0){
this.height = this.height - increment;
}
setTimeout(divAni,delay)
} else {
if(this.height < this.height.needed){
this.height = this.height + increment
}
setTimeout(divAni,delay);
}
}

I'm just not sure how to ascertain how tall the div needs to be for the
content to display.

Jun 24 '06 #1
4 7318
Berko wrote:
I have a javascript that manipulates the DOM with content that will be
of variable heights. How can I ascertain how high my div needs to be in
order to show all content without scroll bars. Rather than just having
this happen automatically, I want the div to expand with a DHTML
animation. So, I need to know where to tell the script to stop
expanding. In pseudo-code:

function divAni(){
if(this.height > 0){
if(this.height > 0){
this.height = this.height - increment;
}
setTimeout(divAni,delay)
} else {
if(this.height < this.height.needed){
this.height = this.height + increment
}
setTimeout(divAni,delay);
}
}

I'm just not sure how to ascertain how tall the div needs to be for the
content to display.


style.height = 'auto';
Jun 25 '06 #2

Aaa aaa wrote:
style.height = 'auto';


That would indeed work for general usage, but I want to animate the
div to display the content, i.e. I want to click on a div and then the
space under it will expand with animation to reveal the content. The
content is created via ajax calls to a web service.

Thanks for the response, but it's not exactly what I was looking for.

Jun 25 '06 #3
Berko wrote:
I'm just not sure how to ascertain how tall the div needs to be for
the content to display.


Load the content. Set visibility='hidden' and then display='block'.
Check the DIV's height.
Set the height to 0px and visibility=''
Now incrementally increase the div height until it matches the measured
height above.

For example, something like this:
http://mattkruse.com/temp/togglediv.html

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jun 26 '06 #4

Matt Kruse wrote:
Berko wrote:
I'm just not sure how to ascertain how tall the div needs to be for
the content to display.


Load the content. Set visibility='hidden' and then display='block'.
Check the DIV's height.
Set the height to 0px and visibility=''
Now incrementally increase the div height until it matches the measured
height above.

For example, something like this:
http://mattkruse.com/temp/togglediv.html

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


Thanks, Matt, this is exactly what I was looking to do!

Jun 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: robert4 | last post by:
I am new to CSS and am trying new things and am stuck at 4 am. The site in question is http://www.robert4.com/test/fitting.html It is just a test page for me to practice with for a bit. My...
7
by: Ladysniper | last post by:
DESPERATE doesn't begin to describe it. Can someone PLEASE tell me what is WRONG with this code? Now..a bit of background. It is a search results page for http://www.azsoma.info/directory.htm....
4
by: reycri | last post by:
I have a page that works as I intend in IE but not in Firefox: <html> <head> <title>Overflow Test</title> </head> <body style='overflow:hidden; margin:0; padding:0;'> <table border='0'...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
3
by: ianv2 | last post by:
Hi I have a div which contains my local navigation bar, which has a blue background and is next to the content div, at the moment however this blue background colour stops after the unordered...
1
by: swc76801 | last post by:
I desperately need help. My understanding of CSS is non-existent. I have a store http://astore.amazon.com/texasheat-20 with Amazon.com. According to the information from Amazon.com "Write your own...
0
by: emanoelmelo | last post by:
Hi I'm having a problem to convert the Solemnity template to wordpress theme. This is the link: www.oficinapublicidade.com/assumpcao As you can see, in FF the sidebar is longer than the...
8
by: Martin Honnen | last post by:
VK wrote: Mozilla has document.height document.width IE has scrollHeight/scrollWidth, depending on compatMode you will need these properties of document.documentElement or document.body --
4
by: AAaron123 | last post by:
<body runat="server" id="MainBody"> <form id="form1" runat="server" style="background-color:green; width: 100%; height: 100%"> <br /> Table1" runat="server" Style="background-color:Yellow;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.