JS Method for dynamically changing the webpage text size in real time based on the browser window size _ javascript skills

Source: Internet
Author: User
This article mainly introduces how JavaScript dynamically changes the text size of a webpage in real time based on the browser window size. It involves related techniques related to dynamic acquisition of page width and Dynamic Calculation of element styles, for more information about how to dynamically change the webpage text size based on the browser window size, see the following example. We will share this with you for your reference. The details are as follows:

At present, with the rem of css3, it has brought unprecedented changes to our mobile development, making our development easier and more compatible with many devices, but this is not the focus of this article. This article focuses on how to use js to change the size of web pages in real time.

The Code is as follows:

Script/* long-width placeholder rem algorithm, which calculates relative rem of each element based on root's rem. The default value is html 320/20 = 16px */function placeholderPic () {var w = document.doc umentElement. offsetWidth; document.doc umentElement. style. fontSize = w/20 + 'px ';} placeholderPic (); window. onresize = function () {placeholderPic ();} script

PS:We recommend a very useful JavaScript compression, formatting, and encryption tool with powerful functions:

JavaScript compression/formatting/encryption tools:Http://tools.jb51.net/code/jscompress

The encryption function in the above js tool can implement eval function encryption of js Code. This site also provides the following decryption tool for eval function encryption, which is very powerful and practical!

Online encryption and decryption tool for js eval Method: Http://tools.jb51.net/password/evalencode

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.