Suppose I have this image:
<img src="images/01.jpg" border="0" rel="shadow" />
Then with jQuery, I get its width using:
$('[rel="shadow"]').width();
Firefox and IE report correct dimensions of the image eg 140px while Chrome reports 0. How to solve this problem?
Note
I don't want to set explicit width for images eg:
<img src="images/01.jpg" border="0" rel="shadow" width="140" />
So, how to get width in cross-browser way which is not defined in width
attribute of elements?
Suppose I have this image:
<img src="images/01.jpg" border="0" rel="shadow" />
Then with jQuery, I get its width using:
$('[rel="shadow"]').width();
Firefox and IE report correct dimensions of the image eg 140px while Chrome reports 0. How to solve this problem?
Note
I don't want to set explicit width for images eg:
<img src="images/01.jpg" border="0" rel="shadow" width="140" />
So, how to get width in cross-browser way which is not defined in width
attribute of elements?
-
What version of Chrome? Is the script inside a
load
event handler or$(document).ready
? – Crescent Fresh Commented Mar 13, 2010 at 19:31 - @Crescent Fresh: Chrome version is: 4.0.295.0 and the script is inside ready. – Sarfraz Commented Mar 13, 2010 at 19:32
- It seems it poses a problem with both Chrome and Safari. – Anthony Forloney Commented Mar 13, 2010 at 19:32
- @Anthony Forloney: any possible solution to this? Is this a bug in those browsers? – Sarfraz Commented Mar 13, 2010 at 19:34
-
1
@loviji: exactly, that's why I asked. The answer is trivial if we know which of
load
orready
is being used. – Crescent Fresh Commented Mar 13, 2010 at 19:39
1 Answer
Reset to default 8$(window).load(
function() {
alert($('img').width());
}
);
This will work: Test case. Basically it will wait until images load before executing the code (when the ready function fires the document has been fully loaded but images haven't).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744767937a4592576.html
评论列表(0条)