js first gets the height of a picture, and then assigns a value to the height of a div. Why is it displayed after refreshing? how to solve it? ask for the elder"s advice. Thank you!
js first gets the height of a picture, and then assigns a value to the height of a div. Why is it displayed after refreshing? how to solve it? ask for the elder"s advice. Thank you!
display
after refreshI guess the process might be like this:
so, your acquisition of offsetHeight
should be done after making sure that the image has been loaded.
my js is at the bottom of the page. My younger brother, a rookie, will trouble the elder to take a look at it again.
can you see if your imgHeight is 0 when it doesn't work? It feels like when performing js, the picture is not loaded and has no height.
Image loading is non-blocking, and the entire execution process needs to be performed after img's onload (or window.onload).