当前位置: 首页 > ai >正文

iframe加载或者切换时候,短暂的白屏频闪问题解决

问题描述

iframe加载或者是切换iframe链接的时候,会有短暂的白屏,这个时候是在加载,目前没有想到避免的问题,应该是浏览器层面的,所以解决方法之一就是,用页面的主题背景色来遮盖一下,当他加载的时候。
这个只是众多方法中的一种

解决

<script setup>
import { ref ,watch} from 'vue'// tab 配置列表
const tabs = [{ label: '业务ss', url: 'http://localhost:5173' },{ label: '状态ss', url: 'http://localhost:5173' },{ label: 'fdfdfdf', url: 'http://localhost:5173/page15' },{ label: 'fsdfdfdfd', url: 'http://localhost:5173/page_strategy' },{ label: 'fsdf管理', url: 'http://localhost:5173' },{ label: 'fdfdfdf总览', url: 'http://localhost:5173' }
]const activeIndex = ref(0)let expanded = true;function toggleSide() {const side = document.getElementById('side');const content = document.getElementById('content');if (expanded) {side.style.width = '2vw'; // 收缩content.style.width = '97vw'} else {side.style.width = '11vw'; // 展开content.style.width = '87vw'}expanded = !expanded;
}// 点击切换按钮的时候,先遮住,再切换iframe
function switchTab(index) {let iframeDom = document.getElementsByClassName('iframe-mask')[0]iframeDom.style.opacity = 1activeIndex.value = index
}// 当iframe加载完成后,立马隐藏遮罩层,注意这里不要加动画给opacity 
function onIframeLoad() {let iframeDom = document.getElementsByClassName('iframe-mask')[0]iframeDom.style.opacity = 0
}</script><template><div><div id="title"></div><div id="middle"><div id="side" @click="toggleSide()"></div><div id="content"><!-- 顶部导航栏 --><div class="top-nav"><divv-for="(tab, index) in tabs":key="index"class="tab":class="{ active: activeIndex === index }"@click="switchTab(index)">{{ tab.label }}</div></div><!-- iframe 区域 --><div class="iframe-wrapper"><iframeclass="iframe-area":src="tabs[activeIndex].url"frameborder="0"@load="onIframeLoad"></iframe><div class="iframe-mask"></div></div></div></div><div id="bottom"></div></div>
</template><style scoped lang="less">
#title {width: 100vw;height: 5.6vh;background-image: url(../public/images/title.jpg);
}
#middle {width: 100vw;height: 89vh;display: flex;#side {width: 11vw;height: 89vh;background-image: url(../public//images/side.png);background-repeat: no-repeat;transition: width 0.3s ease; /* 添加过渡动画 */overflow: hidden;}#content {width: 87vw;height: 87vh;margin-top: 0.8vh;margin-left: 0.6vw;//background-color: aquamarine;/* 顶部导航样式 */.top-nav {height: 3vh;display: flex;//background-color: #e8f6f4;border-bottom: 3px solid #4bb3a4;//padding: 6px;}.tab {padding: 1px 16px;margin-right: 6px;border: 1px solid #48a2a3;border-bottom: none;background-color: #fff;cursor: pointer;user-select: none;border-radius: 3px 3px 0 0;&:hover {background-color: #f0fcfb;}&.active {background-color: #5ecbb8;color: #fff;font-weight: bold;}}// 用到的部分.iframe-wrapper {position: relative;width: 100%;height: 84vh;background-color: red;/* iframe 内容区域 */.iframe-area {flex: 1;width: 100%;height: 84vh;border: none;background-color: #c1eeed;}.iframe-mask {width: 100%;height: 84vh;position: absolute;inset: 0;background: #c1eeed; // 遮罩颜色,可换为 loading 图z-index: 10;pointer-events: none; // 避免遮罩拦截点击// 初始先让他是遮住的,这样当第一次加载的时候,不会出现白屏,等加载完成后,再隐藏opacity: 1;}}}}#bottom {width: 100vw;height: 5vh;background-image: url(../public/images/bottom.jpg);
}
</style>

思路

主要就是当第一次打开页面第一次加载iframe的时候,默认有个遮罩层遮住了,当加载完成的时候,遮罩层立即隐藏,当切换链接的时候,切换前先遮住,然后切换,然后加载完成的时候,遮罩层立即隐藏。


关于其他应用的一些想法

electron 还有 tauri 这些,可以在外面再封装一层c++或者rust的gui,做一个黑色空白页面,打开之后显示的是c++或者rust的gui,当监听到浏览器或者webview加载完成后,立即隐藏,切换成浏览器或者webview的页面,这样应该可以解决打开应用的那一瞬间,由于网页还没有加载造成的白屏频闪现象。

http://www.xdnf.cn/news/7810.html

相关文章:

  • Oracle Enqueue Names
  • MySQL中的重要常见知识点(入门到入土!)
  • QT中信号和事件的区别
  • Panasonic松下焊接机器人节气
  • Web3 领域中的一些专业术语
  • Nginx负载均衡配置详解
  • 14、自动配置【源码分析】-初始加载自动配置类
  • 双活数据中心解决方案
  • KubeVirt虚拟机热迁移
  • 第六章 Freertos智能小车循迹模块
  • 【Oracle 专栏】清理用户及表空间
  • STM32 I2C硬件读写
  • MLXJAX框架学习
  • 时源TS4RPSA2-3-3导电硅胶
  • 【已解决】docker search --limit 1 centos Error response from daemon
  • React中使用 Ant Design Charts 图表
  • 31-35【动手学深度学习】深度学习硬件
  • Spark Core 源码关键环节的深度解析
  • [Vue]跨组件传值
  • PCB 横截面几何形状
  • 几种超声波芯片的特点和对比
  • 【东枫科技】usrp rfnoc 开发环境搭建
  • 学习python day4
  • 101个α因子#11
  • 基于python的机器学习(八)—— 评估算法(一)
  • 力扣周赛置换环的应用,最少交换次数
  • 高阶数据结构——红黑树实现
  • CentOS:搭建国内软件repository,以实现自动yum网络安装
  • Windows逆向工程提升之IMAGE_FILE_HEADER
  • 【Linux笔记】防火墙firewall与相关实验(iptables、firewall-cmd、firewalld)