Javascript-js tutorial

Source: Internet
Author: User
Get the image size (no width or height) and enlarge the image: the private properties of IE are used to prevent serious image distortion! If you are interested, refer 1) Get the image size

The Code is as follows:



Script
Function getWH (t ){
// DOM attributes
Console. log ("width =" + t. width); // 200
Console. log ("height =" + t. height); // 300
// Operation Style
Console. log ("styleWidth =" + t. style. width); // null
Console. log ("styleHeight =" + t. style. height); // null
}


2) Get the image size (without setting the width and height)

The Code is as follows:



Script
Function getWH (t ){
// DOM attributes
Console. log ("width =" + t. width); // 200
Console. log ("height =" + t. height); // 300
// Operation Style
Console. log ("styleWidth =" + t. style. width); // null
Console. log ("styleHeight =" + t. style. height); // null
}


As long as we do not explicitly set it in the style, the width and height will always be blank!

3) Enlarge the image:

Here we use the private properties of IE to prevent serious image distortion!

The Code is as follows:



Script
Function getWH (t ){
T. width * = 2;
T. height * = 2;
// Each click, doubling the width and height
}
Script


4) In FF and Google, we can also use naturalWidth and naturalHeight to get the original image size!

The Code is as follows:



Script
Function getWH (t ){
Console. log ("width =" + t. naturalWidth );
Console. log ("height =" + t. naturalHeight );
T. width = t. naturalWidth * 2;
T. height = t. naturalHeight * 2;
}
Script


NaturalWidth and naturalHeight are only read-only attributes. They cannot be used to set the image size or be continuously zoomed in.

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.