Last active
January 14, 2016 07:55
-
-
Save xiangst0816/697454d1ad9402fba208 to your computer and use it in GitHub Desktop.
根据窗口宽度大小,确定html的fontsize大小,之后用rem作为尺寸单元
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| (function(doc, win) { | |
| var docEl = doc.documentElement, | |
| resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', | |
| recalc = function() { | |
| var clientWidth = docEl.clientWidth; | |
| if (!clientWidth) | |
| return; | |
| //由屏幕宽度得到basefont大小,并将其写入html标签中,文档总的尺寸由rem确定 | |
| docEl.style.fontSize = 100 * (clientWidth / 640) + 'px'; | |
| doc.body.style.display = "block"; | |
| doc.getElementsByTagName('html')[0].removeAttribute('class'); | |
| }; | |
| if (!doc.addEventListener) | |
| return; | |
| win.addEventListener(resizeEvt, recalc, false); | |
| doc.addEventListener('DOMContentLoaded', recalc, false); | |
| })(document, window); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment