My current project involves creating a slideshow in JavaScript where I only want to display half of the images. However, I have encountered an issue with some images having a width and height equal to 0 specifically in Chrome and Opera browsers. What could be causing this inconsistency?
HTML
<img id="picArt" src="0.jpg" onload="resizeImage();" /> <br />
<input type="button" value="Back" onclick="slidePic('P');" />
<input type="button" value="Forward" onclick="slidePic('N');" />
JavaScript
var picArt = document.getElementById("picArt");
var picLocal = new Array();
for(var num=0;num<=17;num++) {
picLocal[num] = String(num) +".jpg";
}
var desrib = new Array();
var preLoad = new Array();
var next = 0, picLength = (picLocal.length-1);
for(var num=0;num <= picLength; num++) {
preLoad[num] = new Image();
preLoad[num].src = picLocal[num];
}
function slidePic (how) {
if(how == "N") next++;
if(how == "P") next--;
if(next> picLength) next =0;
if(next <0) next = picLength;
picArt.src = preLoad[next].src;
}
function resizeImage() {
var originImage = new Image();
originImage.src = picArt.src;
picArt.width = originImage.width/2;
picArt.height = originImage.height/2;
}