Write the following lines in javascript:
(function (doc, win, undefined) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in win? 'orientationchange' : 'resize', recalc = function () { var clientWidth = docEl.clientWidth; if (clientWidth === undefined) return; docEl.style.fontSize = 20 * (clientWidth / 320) + 'px'; }; if (doc.addEventListener === undefined) return; win.addEventListener(resizeEvt, recalc, false); doc.addEventListener('DOMContentLoaded', recalc, false) })(document, window);
The above is the entire content of this article. I hope that the content of this article can bring some help to everyone's study or work. I also hope to support the PHP Chinese website. !
For more articles related to a few lines of js code to achieve self-adaptation, please pay attention to the PHP Chinese website!