Home  >  Article  >  Web Front-end  >  JS method to dynamically change the text size of web pages in real time according to the size of the browser window_javascript skills

JS method to dynamically change the text size of web pages in real time according to the size of the browser window_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:13:451059browse

The example in this article describes the method of JS dynamically changing the text size of web pages in real time according to the size of the browser window. Share it with everyone for your reference, the details are as follows:

At present, the rem of css3 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 Use js to change the size of web page text in real time.

The code is as follows:

<script>
 /* 长宽占位 rem算法, 根据root的rem来计算各元素相对rem, 默认html 320/20 = 16px */
 function placeholderPic(){
  var w = document.documentElement.offsetWidth;
  document.documentElement.style.fontSize=w/20+'px';
 }
 placeholderPic();
 window.onresize=function(){
  placeholderPic();
 }
</script>

PS: Here we recommend a very easy-to-use JavaScript compression, formatting and encryption tool with very powerful functions:

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

The encryption function in the above js tool can realize the eval function encryption form of js code. In this regard, this site also provides the following decryption tool for eval function encryption, which is very powerful and practical!

JS eval method online encryption and decryption tool: http://tools.jb51.net/password/evalencode

Readers who are interested in more JavaScript-related content can check out the special topics on this site: "Summary of JavaScript search algorithm techniques", "Summary of JavaScript animation special effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm techniques", "Summary of JavaScript traversal algorithms and techniques" and "JavaScript Mathematics Summary of operation usage

I hope this article will be helpful to everyone in JavaScript programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn