After setting a src, the width and height won't be available until the
image has loaded (can take 3 or ~ seconds, depending on image size).
You need to trigger the calculation based on an image_1.load event firing.
L
weidc wrote:
hi,
at the moment i'm trying to get the height width of the background
image.
but i always get the width/height of the full size of the div or the
window size.
for example if the image is not big enough for the browser window the
image is more than one time in the screen and i need the width/height
of ONE image and not of the div which is around or so.
so far what i have tried:
//1. ------ returns the full size of the div around
var obj = document.getElementById('bg');
alert('background-image= '+getComputedStyle(obj,'').getPropertyValue
('background-image'));
alert('width= '+getComputedStyle(obj,'').getPropertyValue('width'));
alert('height= '+getComputedStyle(obj,'').getPropertyValue
('height'));
//2. ------ height / width isn't correct either
image_1 = new Image()
image_1.src = url;
DetectImageSize(image_1);
function DetectImageSize(picName,picTitle){
picURL=picName.src
var picwidth = picName.width;
var picheight = picName.height;
}
//3. ------- not correct either
$("body").append('<img id="foto" class="bildmasse" src="'+url+'" />');
alert($("#foto").height()+" "+$("#foto").width()); // returns 18 0
any help would be nice.
------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.387 / Virus Database: 270.13.13/2237 - Release Date: 07/14/09 05:56:00