2025年01月28日 建站教程
移动端页面如何利用js+rem根据不同分辨率自动改变文字和图片大小,下面web建站小编给大家介绍一下!
css样式:
html {
font-size:50px; //默认大小
}
body {
font-size:.3em;
}
js代码:
var view_width, _html
resetSize()
window.onresize = function () {
resetSize()
}
function resetSize() {
view_width = document.getElementsByTagName('html')[0].getBoundingClientRect().width
_html = document.getElementsByTagName('html')[0]
_html.style.fontSize = view_width / 750 * 100 + 'px'
}
本文链接:http://so.lmcjl.com/news/22200/