Home > Web Front-end > JS Tutorial > js or jquery determines whether the image is loaded and implemented code_javascript skills

js or jquery determines whether the image is loaded and implemented code_javascript skills

WBOY
Release: 2016-05-16 17:39:56
Original
847 people have browsed it

Sometimes it is necessary to obtain the width and height of images in web pages to define certain sizes. However, this requires requesting images from the server and downloading them locally. Some js or jquery codes are executed before the images are loaded. . What to do?

jquery provides a method:

Copy code The code is as follows:

01 .$("").load(function(){...});

The selector is the id or class of the image, and the method in function is the callback function. After the image is loaded, After execution, but I have tested a lot, it is not the case at all. The correct solution is:

Use the onload method of js:
Copy Code The code is as follows:

document.getElementById("").onload = function() {};

The experimental result is feasible.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template