antd+全屏的坑(全屏下a-modal/下拉框等不展示)

问题:针对某个元素全屏时,下拉框/弹窗/二次确认窗不展示:下拉框是往body里面插入的,全屏的元素盖住了下拉框。解决:给有下拉框的加入:append-to-body="false"(缺点:每个都需要加,后续加的东西可能会有问题)

针对以上问题解决方案

方案一 :改变挂载对象。挂到根节点上:document.documentElement,再使用定位fixed目标元素,改变z-index。(全屏的还是根节点,全屏时给跟节点加class,再进行fixed)。这样解决会有个问题:position: fixed滚动条不可滚动的坑。

原因:position:fixed进行相对于视口(viewport)的定位,且元素的位置在屏幕滚动时不会改变

解决:当元素祖先的 transform, perspective 或 filter 属性非 none 时,容器由视口改为该祖先。给祖先元素设置一个transform: scale(1)属性即可。

方案二:全屏的时候给顶级元素加上一个class,写一份存在这个class下的样式去display:none需要隐藏的元素,关闭全屏时去掉这个class即可。(这个方式比较简单粗暴)

示例:

javascript 复制代码
// 全屏事件
handleFullScreen(){
    let appDoc = document.getElementById('app-view'); // 找到跟节点加
    appDoc.setAttribute("class", "full-app"); // 加上这个class

    var element = document.documentElement; // 根结点
    // 如果是全屏状态
    if (this.checkFull()) {
        // 如果浏览器有这个Function
        if (document.exitFullscreen) {
            document.exitFullscreen()
        } else if (document.webkitCancelFullScreen) {
            document.webkitCancelFullScreen()
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen()
        } else if (document.msExitFullscreen) {
            document.msExitFullscreen()
        }
        appDoc.removeAttribute("class", "full-app"); // 退出全屏去掉这个class
    } else {
        if (element.requestFullscreen) {
            element.requestFullscreen();
        } else if (element.webkitRequestFullScreen) {
            element.webkitRequestFullScreen();
        } else if (element.mozRequestFullScreen) {
            element.mozRequestFullScreen();
        } else if (element.msRequestFullscreen) {
            // IE11
            element.msRequestFullscreen();
        };
    };
},
css 复制代码
.full-app { // 隐藏不需要展示的元素
    .bg-gradient-wight,
    .eye-hor-layout .ant-layout-sider,
    .eye-ver-layout__header,
    .ant-tabs-bar, 
    .eye-sky-layout .eye-logo, .eye-sky-layout .ant-layout-header  {
        display: none;
    }
    .eye-hor-layout .ant-layout-sider {
        display: none;
    }
}
相关推荐
CN_HW几秒前
Nginx 流量镜像配置文档-双轨国产化
服务器·前端·网络
姑苏倾城客1 分钟前
Flutter中,html 与 dart 桥接沟通
javascript·flutter·html
Java面试题总结7 分钟前
Python 开发技巧 · 高级装饰器 —— 从基础到工业级实战
开发语言·python
JNX_SEMI16 分钟前
ATR2652 GNSS双频LNA:0.75dB噪声系数与22dB高增益设计
前端·单片机·嵌入式硬件·物联网·硬件工程
拾年27531 分钟前
Node.js 异步进化论:从 path 路径拼接到 fs 文件读取,我终于理解了回调地狱的救赎之路
前端·node.js
花颜yyds44 分钟前
React Konva 开发基础速查手册
前端
小粉粉hhh1 小时前
Node.js(五)——编写接口
前端·javascript·node.js
liulilittle1 小时前
Exhaustive drift-fix simulation V2 — KCC on shared-bottleneck wired path.
开发语言·网络·python·tcp/ip·计算机网络·信息与通信·通信
MegatronKing1 小时前
AI时代我们要如何玩抓包测试
前端·后端·测试
uhakadotcom1 小时前
Scrapy-Redis 里面提供哪些即开即用的功能能力模块
前端·面试·github