设置页面满屏背景色
我們常常在工作中遇到,頁面要設(shè)置可視區(qū)域都有背景色,但是 實(shí)際頁面大小并沒有占滿全屏,這個(gè)時(shí)候就會很糾結(jié),這里我記錄一下我的做法。
這里我使用的是vue:
HTML
<template><div class="prize-drop"><div class="prize-drop-content">88888</div></div> </template>JS
mounted: function() {this.setColor();},methods: {setColor() {let divHeight = this.getPrizeDropHeight();let windowHeight = this.getWindowHeight();//當(dāng)頁面實(shí)際高度小于可視區(qū)域高度的時(shí)候,將可視區(qū)域高度 賦值給 實(shí)際高度if (divHeight < windowHeight) {if (document.getElementsByClassName('prize-drop')[0]) {document.getElementsByClassName('prize-drop')[0].style.height = windowHeight + 'px';}}},//獲取當(dāng)前頁面實(shí)際高度getPrizeDropHeight() {return document.getElementsByClassName('prize-drop')[0].offsetHeight;},//獲取可視區(qū)域高度getWindowHeight() {return document.documentElement.clientHeight || document.body.clientHeight;},CSS
.prize-drop {background: #1c2239ff; }總結(jié)
- 上一篇: 再分配包括哪几方面
- 下一篇: 遍历元素根据状态显示不同颜色