IOS微信webview中 @keyframes中 background-size 无效

原写法:
.loading-img {
    width: 1rem;
    height: 1rem;
    position: absolute;
    left:50%;
        top:50%;
    margin-top:-.5rem;
        margin-left:-.5rem;
    -webkit-animation:loadingImg .2s infinite;
}

@keyframes loadingImg {
    from {
        background: url(loading1.png) no-repeat;
                background-size:cover;
    }
    to {
        background: url(loading2.png) no-repeat;
                background-size:cover;
        }
    }
}

期待效果:可以精准还原设计稿适配安卓与IOS系统。

实际效果
  1. 安卓系统可以正常显示
  2. IOS系统 background-size 不生效 背景图展示不全

解决办法

.loading-img {
    width: 1rem;
    height: 1rem;
    position: absolute;
    left:50%;
        top:50%;
    margin-top:-.5rem;
        margin-left:-.5rem;
    -webkit-animation:loadingImg .2s infinite;
    background-size: cover;
}

@keyframes loadingImg {
    from {
        background-image: url(../images/loading1.png);
    }
    to {
        background-image: url(../images/loading2.png);
    }

}
问题总结:
  1. IOS webview存在兼容问题(具体因为什么还没有查到),如果效果一定要用CSS写的话可以选择不将background-size写在@keyframes的动画中。
  2. 尽量将background的属性都分开写,避免执行动画时覆盖原有样式类。
  3. 在网上查阅相关资料时,有网友提出Safari也存在同样问题。
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容