1.监听浏览器视口变化,浏览器视口变化改变某个值a
2.监听值a变化,并且绑定动态样式.
代码如下:
html:
<div class="banner-wrapper" :style="{ top: countTop }"></div>
js:
export default {
mounted() {
window.onresize = () => {
return (() => {
this.viewportHeight = window.innerHeight;
})();
};
},
watch: {
viewportHeight(val) {
let screenHeight = window.innerHeight;
this.countTop = (screenHeight / 3600) * 100 + '%';
},
},
}