Jquery: Get the Image Height or width after page loading _ jquery

Source: Internet
Author: User
In response to project requirements, you need to obtain the Image Height after the page is loaded. In this example, jquery is used to complete this function. For more information, see the following day, this technology also encountered an interesting problem. In response to the project requirements, the height of the image needs to be obtained after the page is loaded, to adjust the position of the overlay layer on the image relative to the top of the image.

But after writing in jquery (function () {/* XXXXXX */}); It is not ideal, because when jquery is ready, at this time, the image has not been loaded in most cases, which can lead to sharp damage ~~~ T ~ T

I just thought about it. It would be nice if jquery had an onload () method with js ~ It's really a big shit in the sky. It happened to hit Ben diaosi ~~ I searched the internet and found this method. The method is as follows:

The Code is as follows:


$ (Window). load (function (){
Alert ("do you guess the image has been loaded? ");
});


Ben diaosi saw this method, as if he saw a piece of golden shit in the slums ~~ Hurry up and try again ~~~ Wow ~~~ Wow ~~~ Great! Actually solved it!

I have to admire the strength of jquery! The Code is as follows:

The Code is as follows:


JQuery (function (){
JQuery (window). load (function (){
/* Perform operations on the image to obtain the img height, width, and some column operations! */
});
});

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.