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