473,414 Members | 1,663 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,414 software developers and data experts.

getting computed style for Img width and height

For Firefox, we can get the computed style of an Img element, using
the script in

http://www.quirksmode.org/dom/getstyles.html

so even if we set only the width of an Image in CSS, we will get both
the width and height of the final rendered image.

However, it won't work in IE 7.... the width will return the original
value, but the height is "NaN".... is there a way to get the final
rendered width and height of an image in both Firefox and IE?
Jun 27 '08 #1
2 3294
liketofindoutwhy <li**************@gmail.comwrites:
For Firefox, we can get the computed style of an Img element, using
the script in

http://www.quirksmode.org/dom/getstyles.html

so even if we set only the width of an Image in CSS, we will get both
the width and height of the final rendered image.
I would use offsetHeight / offsetWidth for that instead. I'm not
convinced width and height *should* be part of the computed style, and
also, computed styles may be returned *any* supported unit, while
offsets are always given in pixels (which is usually what you want).

Offsets are mentioned in the first paragraph of javascript code on the
page you linked.
However, it won't work in IE 7.... the width will return the original
value, but the height is "NaN".... is there a way to get the final
rendered width and height of an image in both Firefox and IE?
Re-read that page.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #2
On Apr 22, 10:59 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
liketofindoutwhy <liketofindout...@gmail.comwrites:
For Firefox, we can get the computed style of an Img element, using
the script in
http://www.quirksmode.org/dom/getstyles.html
so even if we set only the width of an Image in CSS, we will get both
the width and height of the final rendered image.

I would use offsetHeight / offsetWidth for that instead. I'm not
convinced width and height *should* be part of the computed style, and
also, computed styles may be returned *any* supported unit, while
offsets are always given in pixels (which is usually what you want).

Offsets are mentioned in the first paragraph of javascript code on the
page you linked.
However, it won't work in IE 7.... the width will return the original
value, but the height is "NaN".... is there a way to get the final
rendered width and height of an image in both Firefox and IE?

Re-read that page.
eh, that's right, offsetWidth and offsetHeight do work... and
clientWidth, scrollWidth also work... I wonder why the later 2 are
less known and not even in the Definitive Javascript book.
clientWidth is more accurate width for the image as it doesn't include
the border, if any, for the image. scrollWidth is always the same as
offsetWidth even if i resize my window... i can't make them different.

Jun 27 '08 #3

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

Similar topics

15
by: middletree | last post by:
How do I request the actual page name that I'm on? This is going to go into an include file, and depending on which page I'm on, I'd like to do different things. I'm looking for "pagename.asp"
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
4
windows_mss
by: windows_mss | last post by:
When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map... hi, i can able to get the Correct Route and Path for the corresponding Source and destination, like...
7
by: raylaur | last post by:
I'm using a javascript "slide" function to move a <div> layer in 10 pixel increments from one location on a page to another. The layer contains a GIF image. It's basically a side panel that flies out...
1
epots9
by: epots9 | last post by:
I have a image inside of a div <div id="image"> <div id="loader"> <img id="loaderImage" src="assets/loader.gif" alt="loading..." /> </div> <div id="loaded"> <img id="picture" src="" alt=""...
29
by: Chris Riesbeck | last post by:
I have an image with a class and the class defines a clip rectangle. In Firefox 2 and 3, and Opera 9, I can access the rectangle with document.defaultView.getComputedStyle(). But that doesn't...
2
by: GTalbot | last post by:
Hello fellow comp.infosystems.www.authoring.stylesheets colleagues, Imagine this situation: #grand-parent-abs-pos { height: 400px; position: absolute; width: 600px; }
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.