您现在的位置是:网站首页> 编程资料编程资料
快速解决css使用@keyframes加载图片首次循环时出现白色间隙问题(闪屏)详解CSS 去掉inline-block元素间隙的几种方法 CSS图片下面有间隙的6种解决方案css几种解决inline-block间隙的方案(整理)css解决display:inline-block;产生的缝隙(间隙)的方法详解CSS清除图片下几像素空白间隙的方法
2021-09-03
971人已围观
简介 这篇文章主要介绍了快速解决css使用@keyframes加载图片首次循环时出现白色间隙问题(闪屏),本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
问题解说:
在使用css 的animations 属性时,首次加载循环会出现白色的间隙,看着有点像页面有刷新的感觉,后面每次循环就不会再有这个问题
问题演示
//html//less .container { width: 100vw; height: 100%; } .container .first { width: 100vw; height: 100vh; animation: bgmove 10s infinite; } @keyframes bgmove { 0% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-1.jpg") no-repeat center center; background-size: cover; opacity: 1; } 15% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-1_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 30% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-2_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 45% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-4_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 60% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-5_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 80% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-1_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 100% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-1.jpg") no-repeat center center; background-size: cover; opacity: 1; } }
解决办法
//less .container { width: 100vw; height: 100%; } .container .first { width: 100vw; height: 100vh; background:url("https://sqimg.qq.com/qq\_product\_operations/im/pcqq/9.0/firstscreen\_img/BG-1.jpg"), url("https://sqimg.qq.com/qq\_product\_operations/im/pcqq/9.0/firstscreen\_img/BG-1\_1.jpg"), url("https://sqimg.qq.com/qq\_product\_operations/im/pcqq/9.0/firstscreen\_img/BG-2\_1.jpg"), url("https://sqimg.qq.com/qq\_product\_operations/im/pcqq/9.0/firstscreen\_img/BG-4\_1.jpg"), url("https://sqimg.qq.com/qq\_product\_operations/im/pcqq/9.0/firstscreen\_img/BG-5\_1.jpg"), url("https://sqimg.qq.com/qq\_product\_operations/im/pcqq/9.0/firstscreen\_img/BG-1\_1.jpg"); animation: bgmove 10s infinite; } @keyframes bgmove { 0% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-1.jpg") no-repeat center center; background-size: cover; opacity: 1; } 15% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-1_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 30% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-2_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 45% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-4_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 60% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-5_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 80% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-1_1.jpg") no-repeat center center; opacity: 1; background-size: cover; } 100% { background: url("https://sqimg.qq.com/qq_product_operations/im/pcqq/9.0/firstscreen_img/BG-1.jpg") no-repeat center center; background-size: cover; opacity: 1; } }最终效果
问题解析
图片的加载一般有两种情况, 图片的预加载 和 图片的懒加载 ,在这里就涉及到图片的预加载问题,当页面的图片过多的时候,服务器的压力就会大,加载图片一次性显示会有不连贯所以在第一次将所有的图片都加载下来,这样后面在使用这些图片的时候就是缓存在本地的资源,加载速度也会块很多,就不会出现白色断层
到此这篇关于快速解决css使用@keyframes加载图片首次循环时出现白色间隙问题(闪屏)的文章就介绍到这了,更多相关css keyframes加载图片内容请搜索以前的文章或继续浏览下面的相关文章,希望大家以后多多支持!
相关内容
- CSS中元素的显示模式详解CSS标签中的显示模式一文了解CSS 标签显示模式
- CSS3标注引用的出处和来源的方法
- 面试官提问之CSS如何实现固定宽高比CSS背景图片固定宽高比自适应调整的实现方法
- CSS 有序或者无序列表的前面的标记 list-style-type 属性的实现CSS字体、文本、列表属性详细介绍css中有序无序列表项list样式设置方法使用CSS计数器美化数字有序列表的实现方法
- CSS3属性 line-clamp控制文本行数的使用CSS flex-basis 文本溢出问题的解决移动端的text-overflow多行文本溢出显示省略号(…)css多行文本溢出时出现省略号的示例html文本溢出显示省略字符的两种常用解决方法纯CSS定制文本省略的方法大全CSS实现单行、多行文本溢出显示省略号的实现方法css实现文本溢出显示省略号CSS实现限制字数功能当对象内文本溢出时显示省略标记用css截取字符实现文字自动截断隐藏溢出文本溢出文本text-overflow的使用问题分析及解决
- 详解CSS中的flex布局深入浅析CSS3中的Flex布局整理CSS实现动态图片的九宫格布局的实例代码css之display属性之inline-block布局实现详解css用Flex布局制作简易柱状图的实现使用CSS和Java来构建管理仪表盘布局的实例代码
- css用Flex布局制作简易柱状图的实现深入浅析CSS3中的Flex布局整理CSS实现动态图片的九宫格布局的实例代码css之display属性之inline-block布局实现详解详解CSS中的flex布局使用CSS和Java来构建管理仪表盘布局的实例代码
- 利用css样式实现表格中字体垂直居中的方法CSS3 不定高宽垂直水平居中的几种方式CSS3实现水平居中、垂直居中、水平垂直居中的实例代码手把手教你CSS水平、垂直居中的10种方式(小结)css常用元素水平垂直居中方案css布局教程之如何实现垂直居中CSS实现垂直居中的几种方法小结CSS垂直居中的另类实现代码详解(不走寻常路)
- CSS变量实现暗黑模式的示例代码纯CSS免费让网站拥有暗黑模式切换功能的实现代码Html页面支持暗黑模式的实现详解Html5项目适配系统深色模式方案总结
- CSS 中px、em、rem、%、vw、vh单位之间的区别详解浅析CSS中单位px、rem、em、vh、vw之间的区别CSS3移动端vw+rem不依赖JS实现响应式布局的方法css3中单位px,em,rem,vh,vw,vmin,vmax的区别及浏览器支持情况浅析rem和em和px vh vw和% 移动端长度单位如何利用vw+rem进行移动端布局
