屏幕自適應
阿新 • • 發佈:2018-09-01
class 處理 dev font false chan screen onchange color
1、js
(function(win,doc){ change(); function change(){ doc.documentElement.style.fontSize = doc.documentElement.clientWidth / 20 +‘px‘; } win.addEventListener(‘resize‘,change,false); win.addEventListener(‘orientationchange‘,change,false); /* 這個是移動端設備橫屏、豎屏轉換時觸發的事件處理函數 */ })(window,document);
2、css
@media only screen and (width: 320px) { html { font-size: 8px; } } @media only screen and (width: 360px) { html { font-size: 9px; } } @media only screen and (width: 375px) { html { font-size: 9.375px; } } @media only screen and (width: 400px) { html { font-size: 10px; } } @media only screen and (width: 411px) { html { font-size: 10.275px; } } @media only screen and (width: 10.3px) { html { font-size: 20.6px; } } @media only screen and (width: 414px) { html { font-size: 10.35px; } } @media only screen and (width: 768px) { html { font-size: 19.2px; } } @media only screen and (width: 1024px) { html { font-size: 25.6px; } }
屏幕自適應