關於華爲虛擬操做鍵收起後頁面高度不會刷新問題的總結

狀況一:
在下圖佈局下:
圖片描述佈局

頭部一個固定的banner圖,下部爲佔滿屏幕的一個元素時.開始的思路是獲取屏幕的高度減banner的高度,賦值給底部高度。此時,會出現帶着虛擬鍵盤進來,再關閉虛擬鍵盤,底部留白的結果;
代碼以下:this

setHeigh(){
                var bodyTop = document.body.offsetHeight || document.documentElement.offsetHeight;
                var bannerH = document.getElementsByClassName('issue_banner')[0].offsetHeight;

                function getStyle(obj, attr) {
                    if (obj.currentStyle) {
                        return obj.currentStyle[attr];
                    }
                    else {
                        return document.defaultView.getComputedStyle(obj, null)[attr];
                    }
                }

                var marginTop = getStyle(_this.$refs.wrap, 'marginTop');
                _this.$refs.wrap.style.height = bodyTop - bannerH - marginTop.replace(/px/i, '') + 'px';
                }

解決方法:結合position:absolute;屬性限定底部元素的高度。bottom_box加底部定位和頂部定位給出元素高度。此時,js只需動態獲取banner的高賦值給底部的top屬性就好。spa

.bottom{
        position: absolute;
        width: 100%;
        margin-top: 0.12rem;
        background: #FFFFFF;
        overflow: hidden;
        bottom: 0;
    }
setHeight: function () {
                var _this = this;
                var bannerH = document.getElementsByClassName('issue_banner')[0].offsetHeight;
                _this.$refs.wrap.style.top = bannerH + 'px';
            },
相關文章
相關標籤/搜索