Note that there are some explanatory texts on larger screens.

plurals
  1. POhow does chrome render a picture after
    primarykey
    data
    text
    <p>I just find an interest thing, when you change an element's src, it'll have several seconds delay and the line under it will execute before new picture rendered, so it'll load latter picture's size(width height) if you want to get the size immediately after change a picture's src.</p> <p>heres the evidence:</p> <p><code> $("button").click(functon() { //set a button so you can handle the process.</p> <pre><code>var alert1 = $("#image").width(); //#image is an &lt;img&gt; element, don't set width and height. var src = pictures.pop(); //pictures is an array which stored image base64 code. $("#image").attr("src", src); var alert2 = $("#image").width(); alert("alert1: " + alert1 + " alert2: " + alert2); </code></pre> <p>} </code></p> <p>as the code shows, after it executed, the alert1 should show the width of the picture before change src, alert2 should show the width of picture after change src.</p> <p>but what i actually see? both alert1 and alert2 all show the width of picure befor change src.</p> <p>to enhance my opinion, there's another exp:</p> <p><code> $("button").click(functon() { //set a button so you can handle the process.</p> <pre><code>var alert1 = $("#image").width(); //#image is an &lt;img&gt; element, don't set width and height. var src = pictures.pop(); //pictures is an array which stored image base64 code. $("#image").attr("src", src); alert("wait"); var alert2 = $("#image").width(); alert("alert1: " + alert1 + " alert2: " + alert2); </code></pre> <p>} </code></p> <p>see? i add an alert box after change src so i can control the code to execute after change src, then what happened, the alert1 return the width of picture before change src and the alert2 return the width of picture after change src! so it's proved that the process of src is done after the code after it executed.</p> <p>What I want to know is why this happen, what happened when chrome change picture's src?</p> <p>ps: I just try this on chrome, if you are interested in this can do the same exp on other browdser.</p>
    singulars
    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.
    1. This table or related slice is empty.
    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