1. 程式人生 > >移動端適配js

移動端適配js

使用 ont ldo fontsize phone AS cli width col

1       //得到手機屏幕的寬度
2       let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
3       //得到html的Dom元素
4       let htmlDom = document.getElementsByTagName(html)[0];
5       //設置根元素字體大小 為什麽除以20,因為我們是以iphone5為標準,它的width為320,font-size為16
6       htmlDom.style.fontSize= htmlWidth/20
+ px;

這樣就可以和rem配合使用,實現移動端的適配了

移動端適配js