jquery realizes the method of changing picture size after the picture loading completes _jquery

Source: Internet
Author: User

The example of this article describes the method of jquery to change the image size after the picture loading is completed. Share to everyone for your reference, specific as follows:

To change the size of the picture is not difficult, you can use jquery to manipulate CSS changes. But the premise is to determine whether the picture is loaded and completed. The main thing is to judge the state by the load events and onreadystatechange of jquery.

For IE6, onreadystatechange can be directly processed, in the IE7, you need to use a timer to determine the readystate state of the picture. And for FF and Chrome just can be judged directly by the Load event.

The following is the complete code used in the instance:

<script type= "Text/javascript" > $ (document). Ready (function () {function changesize (obj) {//
   This function is used to set the size of the picture when the picture is loaded w=obj.width ();
   H=obj.height ();
   T=obj.attr ("title");
   Src=obj.attr ("src");
   Obj.width (W&GT;400?400:W); Obj.height (w>400?) (
   400/W) *h:h);
   OBJ.CSS ("cursor", "pointer");
     Obj.click (function () {$ ("#picDlg"). HTML ("

The picture above can be scaled down to show the picture in the article, while using the jquery dialog UI component when clicking the picture, display the full-size picture at one level.

More interested readers of jquery-related content can view this site: "jquery switching effects and tips summary", "jquery drag and drop effects and tips summary", "JQuery Extended Skills Summary", "jquery common Classic Effects summary", " jquery animation and special effects usage summary, "jquery selector usage Summary" and "jquery commonly used plug-in and usage summary"

I hope this article will help you with the jquery program design.

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.