jquery implements a method of automatically scaling a picture based on the size of the browser window _jquery

Source: Internet
Author: User

This article illustrates how jquery implements automatic scaling of pictures based on the size of the browser window. Share to everyone for your reference. as follows:

(function ($) {$.fn.resizeimage = function () {var imgload = function (URL, callback) {var img = new Image ();
   img.src = URL;
   if (Img.complete) {callback (img.width, img.height);
     else {img.onload = function () {callback (img.width, img.height);
    Img.onload = null;
   };
  };
  };
  var original = {width:$ (window). width ()};
   Return This.each (function (i,dom) {var-image = $ (this); Imgload (image.attr (' src '), function () {var img = {width:image.width (), Height:image.height ()},percentag
    e=1;
    if (img.width<original.width) {percentage = 1;
    }else{percentage = (original.width)/img.width;
    } image.width (img.w=img.width*percentage-30). Height (img.h=img.height*percentage);
     $ (window). Resize (function () {var w = $ (this). width ();
     Percentage = w/img.width>1?1:w/img.width;
     var newwidth = img.width*percentage-30;
     var newheight = img.height*percentage; Image.width (newwidth). Height (nEwheight);
   });
  });
 });
};

 }) (JQuery);

I hope this article will help you with your jquery programming.

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.