解决浏览器在局部区域全屏下,elementUI部分弹窗组件无法正常显示的问题,如Notification,Message等

项目场景:

使用screenfull.js将特定区域局部全屏,全屏状态下,服务器推送消息,前端使用Notification组件弹窗显示。


问题描述

局部全屏下,收到推送消息时,不能正常显示,需取消全屏才能看到。

import screenfull from 'screenfull'
// 全屏
handleScreen() {
    //screenfull.isEnabled  此方法返回布尔值,判断当前能不能进入全屏
    if (!screenfull.isEnabled) {
        return false
    }
    //screenfull.toggle 此方法是执行全屏化操作。如果已是全屏状态,则退出全屏
    screenfull.toggle(this.$refs.fullscreen)
},
this.$notify({
    title:'报警提示',
    message:message+new Date(),
    duration:0,
    type:'warning',
    offset:100
})

原因分析:

elementUI的Notification组件是插入了body中,局部全屏状态下,把body界面覆盖,故无法正常显示。经测试,即使将Notification组件的层级改变为z-index:9999, 亦无法显示。


解决方案:

我们不妨换个思路,既然直接将需要全屏的div节点传入screenfull中会导致通知无法显示,不如就将body直接全屏,再通过改变CSS使这个div全屏显示,当取消全屏时,再将这个div恢复到原位置。

测试的div

<div
ref="fullscreen"
:class="{'full':isFull}"
id="test"
@mousemove="get"
:style="{'left':fastartLeft+'px','top':fastartTop+'px'}">
    <el-button type="primary" icon="el-icon-full-screen" circle @click="handleScreen"></el-button>
    <el-button type="danger" icon="el-icon-delete" circle @click="closeNotice"></el-button>
    <!-- <h1>测试实现移动和拖拽</h1> -->
    <p>鼠标坐标:</p>
    <p>{{left}}</p>
    <p>{{top}}</p>
    <p>移动元素的坐标</p>
    <p>{{positionx}}</p>
    <p>{{positiony}}</p>
    <div 
    id="son"
    @mousedown="move" 
    :style="{'left':positionx+'px','top':positiony+'px'}">
        <p>元素可移动</p>
    </div>
</div>

CSS
注意:full中z-index关键,必须小于2000,因为Notification组件默认z-index为2000

#test {
    background: yellowgreen;
    margin-right: 20px;
    height: 500px;
    color: white;
    position: relative;
}
#son {
    width: 100px;
    height: 100px;
    background:rgb(248, 160, 160);
    position: absolute;
}
.full{
    position:fixed !important;
    z-index:200;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100% !important;
}

isFull为当前全屏状态,为布尔值

data(){
	return{
		isFull:false
	}
},
created(){
    this.init()
},

进页面初始化,监听全屏状态并赋值给isFull,isFull为true时,动态给div添加样式full

init(){
    if (screenfull.isEnabled) {
        screenfull.on('change',this.change)
    }
},
change(){
    this.isFull = screenfull.isFullscreen
    // console.log(this.isFull)
},

将body全屏,传入body节点

// 全屏
handleScreen() {
    //screenfull.isEnabled  此方法返回布尔值,判断当前能不能进入全屏
    if (!screenfull.isEnabled) {
        return false
    }
    const bodyNode = document.querySelector('body')
    //screenfull.toggle 此方法是执行全屏化操作。如果已是全屏状态,则退出全屏
    screenfull.toggle(bodyNode)
},

没有全屏下的页面

在这里插入图片描述

此div全屏下,通知可正常显示,成功解决!

在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
作为一个 AI,我没有真正的印象,但是我可以告诉你一些 elementUI 组件的特点和使用场景,供你参考。 1. Button 按钮组件:在 Web 开发中,按钮是非常常见的交互元素,elementUI 的 Button 组件提供了多种风格和尺寸的按钮,可以满足不同的设计需求。例如: ``` <el-button>默认按钮</el-button> <el-button type="primary">主要按钮</el-button> <el-button type="success">成功按钮</el-button> <el-button type="warning">警告按钮</el-button> <el-button type="danger">危险按钮</el-button> ``` 2. Input 输入框组件:在表单开发中,输入框是必不可少的元素,elementUI 的 Input 组件提供了多种类型和尺寸的输入框,可以满足不同的输入需求。例如: ``` <el-input placeholder="请输入内容"></el-input> <el-input type="password" placeholder="请输入密码"></el-input> <el-input-number v-model="num" :min="1" :max="10"></el-input-number> <el-autocomplete :fetch-suggestions="querySearch" placeholder="请输入内容"></el-autocomplete> ``` 3. Table 表格组件:在数据展示和编辑中,表格是非常常见的元素,elementUI 的 Table 组件提供了强大的数据展示和编辑功能,支持排序、筛选、分页、自定义列等多种功能。例如: ``` <el-table :data="tableData"> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="age" label="年龄"></el-table-column> <el-table-column prop="address" label="地址"></el-table-column> </el-table> ``` 除了上述组件elementUI 还提供了很多其他常用的组件,如 Select、DatePicker、Dialog、MessageNotification 等,它们都具有易用性、美观性和可定制性的特点,广泛应用于各种 Web 开发场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值