vue移动端安卓软键盘弹出底部按钮顶起

2022-12-08 15:13:33
2024-04-18 05:54:22

解决方案

<template>
    <view class="bg">
        <input type="text" />

        <!-- 定位元素 -->
        <view class="btn" v-if="hidshow"></view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            //默认屏幕高度
            docmHeight: document.documentElement.clientHeight || document.body.clientHeight,
            //实时屏幕高度
            showHeight: document.documentElement.clientHeight || document.body.clientHeight,
            //显示或者隐藏定位元素
            hidshow: true
        };
    },
    mounted() {
        //开始监听
        window.addEventListener('resize', this.listenResize);
    },
    methods: {
        listenResize() {
            this.showHeight = document.body.clientHeight;
        }
    },
    beforeDestroy() {
        //销毁
        window.removeEventListener('resize', this.listenResize);
    },
    watch: {
        //改变高度,就判断是否显示高度是否小于屏幕高度
        showHeight: function () {
            if (this.docmHeight > this.showHeight) {
                this.hidshow = false;
            } else {
                this.hidshow = true;
            }
        }
    }
};
</script>

<style lang="scss" scoped>
.bg {
    width: 100%;
    height: 100vh;
    background-color: red;

    .btn {
        width: 100%;
        height: 100px;
        background-color: rgb(255, 255, 255);
        position: fixed;
        bottom: 0;
    }
}
</style>
目录
暂无评论,欢迎留下你的评论

运营需要亿点资金维持,您的支持,是小白龙创作的动力!!!

昵称
留言
赞赏金额