学习目标:
1、rem
学习内容:
1
rem指html.body{font-size: 10px}设置的值(此处1rem=10px)
html中
<template>
<div id="rightBox1" :style="{ height: pdfheight }">
</div>
</template>
<script>
window.onload=function(){ (function(){
var html = document.documentElement;
var windowWidth = html.clientWidth;
html.style.fontSize = windowWidth /15+ 'px';
})();}
data() {
return {
pdfheight: (window.innerHeight - 110) / 10 + "rem",
}
}
mounted() {
window.addEventListener("resize", () => {
this.pdfheight =(window.innerHeight - 110) / 50 + "rem";
});
}
</script>
学习Tips:
- window.onload()方法用于在 HTML 文档加载完毕后立刻执行.
常用在:< script >中写代码,操作下文< body >
(若不用,script时未渲染出body,无法获得id=bg)
<script type="text/javascript">
window.onload=function(){
function runoob1(){
document.getElementById("bg").style.backgroundColor="#F00";
}
runoob1();
}
</script>
</head>
<body>
<div id="bg"></div>
</body>
- document.documentElement 返回文档的 documentElement:
HTML 文档返回对象为HTML元素,如果 HTML 元素缺失,返回值为 null。