I have no JavaScript knowledge. I'm trying to delay the $('#image').reel
code until the image is loaded so I can get the image width value.
stitched: imgwidth,
loops: false,
frames: 30,
frame: 1,
wheelable: false
// speed: 0,
// timeout: 1
});
function imageReel() {
$('#image').empty();
var image = '<img id="image" src=\'images/' + arrReel[imgcount] + '.png\' width="1000" height= "700" />';
$('#image-wrapper').html(image);
$('#image').reel({
stitched: imgwidth,
loops: false,
frames: 30,
frame: 1,
wheelable: false
// speed: 0,
// timeout: 1
});
console.log(imgwidth);
}
Attempt 1 based on first answer
$('#image').empty();
// var image = '<img id="image" src=\'images/'+arrReel[imgcount]+'.png\' width="1000" height= "700" />';
$(function(){
image=new Image();
image = '<img id="image" src=\'images/'+arrReel[imgcount]+'.png\' width="1000" height= "700" />';
image.onload=function(){
$('#image-wrapper').html(image);
$('#image').reel({
stitched: imgwidth,
loops: false,
frames: 30,
frame: 1,
wheelable: false,
// speed: 0,
// timeout: 1
});
};
$('body').append(image);
});
Result. Still gives me 0 width plus creates multiple images
Attempt 2 based on kilian's answer
<div id="image-wrapper"><img id="image" src='images/outsidedark.png' width="1000" height= "700" onload="someFunction()" /></div>
function someFunction()
{
console.log(imgwidth);
$('#image').reel({
// stitched: 3208,
stitched: imgwidth,
loops: false,
frames: 30,
frame: 1,
wheelable: false,
// speed: 0,
// timeout: 1
});
}
Result The image keeps getting loaded. Possible because of the plugin but I think I need onload to only load that function once and its loading it multiple times. The width is still 0 and because of the console log that 0 keeps getting displayed like its stuck in an infinite loop.