Pixel (PX) to other length units (mm, CM ...)

Source: Internet
Author: User

Today, we want to convert Px to mm, because the size of the pixel-to-other unit ratio varies with the resolution size set on the screen, so it cannot be calculated using a fixed number.

Solution:

Put a hidden block with a height of 1mm on the page <Div id = "divmmheight" style = "height: 1mm; display: none;"> </div>,

Then use jquery to get its height var mmtopx =$ ("# divmmheight"). Height (); the height of mmtopx is the PX size corresponding to 1mm,

The next step is to get the pixel height calculation of the object and get the length in mm unit after division with this ratio.

The same applies to other units.

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.