Usually we judge the size of js images by using the images object, and then using attr to get the image address and then judging . Let’s take a look at some examples.
Easiest way:
In the above example, if the page has not been loaded, js will not be able to obtain the image size. For this, we can first determine whether the loading is complete and then determine the image size.
Or use jquery:
Now we can optimize the code
Note here: #tlogo is an ID added to your picture address. This is required.