Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I delay JavaScript code until all the images are loaded into memory
    primarykey
    data
    text
    <p>I have no JavaScript knowledge. I'm trying to delay the <code>$('#image').reel</code> code until the image is loaded so I can get the image width value.</p> <pre><code> stitched: imgwidth, loops: false, frames: 30, frame: 1, wheelable: false // speed: 0, // timeout: 1 }); function imageReel() { $('#image').empty(); var image = '&lt;img id="image" src=\'images/' + arrReel[imgcount] + '.png\' width="1000" height= "700" /&gt;'; $('#image-wrapper').html(image); $('#image').reel({ stitched: imgwidth, loops: false, frames: 30, frame: 1, wheelable: false // speed: 0, // timeout: 1 }); console.log(imgwidth); } </code></pre> <p><strong>Attempt 1 based on first answer</strong></p> <pre><code> $('#image').empty(); // var image = '&lt;img id="image" src=\'images/'+arrReel[imgcount]+'.png\' width="1000" height= "700" /&gt;'; $(function(){ image=new Image(); image = '&lt;img id="image" src=\'images/'+arrReel[imgcount]+'.png\' width="1000" height= "700" /&gt;'; 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); }); </code></pre> <p><strong>Result. Still gives me 0 width plus creates multiple images</strong></p> <p><strong>Attempt 2 based on kilian's answer</strong></p> <pre><code> &lt;div id="image-wrapper"&gt;&lt;img id="image" src='images/outsidedark.png' width="1000" height= "700" onload="someFunction()" /&gt;&lt;/div&gt; function someFunction() { console.log(imgwidth); $('#image').reel({ // stitched: 3208, stitched: imgwidth, loops: false, frames: 30, frame: 1, wheelable: false, // speed: 0, // timeout: 1 }); } </code></pre> <p><strong>Result</strong> 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. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload