停止css @keyframes动画

解决方法来源
display重绘异步事件

场景:在做一个基于Vue ElementUI后台系统页面loading的时候,遇到了给v-loading加动画,却会阻塞v-loading结束自动display: none的问题,导致必须等动画时长走完,蒙层才none,才可以点击页面。

机制:由于display:none会引起页面的重绘事件,所以它是一个异步的延时事件,所以浏览器其实会先解析animate的代码,然后再执行display:none。

代码如下,必须加入 animation: none !important 停止动画,否则会有'阻塞'效果。还有一种暂停动画的方法,试过没起作用 animation-play-state: paused; 。

css 复制代码
.el-loading-mask {
  background: rgba(255, 255, 255, .1);
  backdrop-filter: blur(3px);
  background-image: url("../assets/images/XOsX.gif");
  background-size: 80px 80px;
  background-repeat: no-repeat;
  background-position: center;
  position: absolute;
  animation: comeup 10s infinite; // 动画
  .el-loading-spinner {
    display: none !important
  }
}
.el-loading-fade-leave-active{
  animation: none !important; // 删除动画(解决动画时长阻塞display:none问题)
}
@keyframes comeup {
  0%{background-size: 80px 80px;}
  90%{background-size: 210px 210px;}
  100%{background-size: 220px 220px;}
}
相关推荐
贺今宵3 分钟前
Vue 3 + Capacitor 使用jeep-sqlite,web端使用本地sqlite数据库
前端·数据库·vue.js·sqlite·web
taocarts_bidfans6 分钟前
Google Indexing API 外贸独立站主动推送收录实战开发
前端·独立站·外贸独立站·taoify
lichenyang45323 分钟前
鸿蒙 Stage 模型到底是什么?一篇讲清 Ability、EntryAbility 和入口文件为什么这么设计
前端
ihuyigui40 分钟前
国际商超零售短信接口
大数据·前端·后端·架构·零售
Yan-英杰40 分钟前
从零玩转搜索引擎 API: 多引擎整合实战
服务器·前端·microsoft
Spider_Man1 小时前
Claude Code Hooks:给 AI 助手装上"安全带"
前端·ai编程·claude
lichenyang4531 小时前
HarmonyOS 6.0 ArkUI 循环渲染:ForEach、LazyForEach 和 Repeat 到底怎么选?
前端
Captaincc1 小时前
置身钉内:一个 AI 办公产品的理想、失焦与组织困境
前端·程序员
零陵上将军_xdr1 小时前
后端转全栈学习-Day6-JavaScript 基础-4
前端·javascript·学习
梦幻通灵2 小时前
Vue3 Element日期控件置灰明天之后日期
前端·javascript·vue.js