Updated with the media array.
I need to get the width and height of som media (images and videos).
I am using a for loop and onload/eventlistner to get this, but if I have more then one media of the same kind, I only get the data of the first one. (I have to use old javascript so no foreach because it will not be used in an ordinary browser)
var imgSrc = 'fallBack.png';
var imgType = 'photo';
var screenW = document.body.clientWidth;
var screenH = document.body.clientHeight;
images = [
{media: { type: "photo", media: "image1.png" }},
{media: { type: "photo", media: "image1.png" }}
]
for (var i = 0; i < images.length; i++) {
var img = new Image();
img.onload = function() {
console.log(this); // this just shows for the first image in the list with two images
//Simplefying what I want out of this
If(this.width < this.height && screenW < screenH) {
imgSrc = this.src;
imgType = "photo"
};
2
Answers
Just create an array and store the images into it.
Additionally, removed
setTimeout
and added a simple counterloadedImagesCount
andcheckAllImagesLoaded
which checks if the counter is equal to the size of images.Here is a version that counts the loads and displays when done