gpt4 book ai didi

IE11中的CSS动画背景-位置

转载 作者:太空宇宙 更新时间:2023-11-04 06:04:03 33 4
gpt4 key购买 nike

我正在尝试创建一个 CSS 动画,它在 sprite 表中循环播放 16 个图像,给人一种幽灵“漂浮”的错觉。动画通过在 background-position 位置之间移动以显示不同状态的幽灵来实现这一点。

enter image description here

在 Chrome、Firefox 和 Safari 中它运行良好。在 IE11 中它没有。

(Browserstack 测试表明它在 Edge 中确实有效。)

我在网上看到 IE 不支持 background-images 的动画,但这是 background-position。也许这就是问题所在。

这里是代码,或者一个 JSFiddle 来帮助:https://jsfiddle.net/nuw1ypfm/6/

.ghost {
width: 64px;
height: 64px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50% -50%);
-webkit-transform: translate(-50% -50%);
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACDCAYAAABFqhNlAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugd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MDYJXPzbzhn6jFl4tfBvFYDZ/x4DmPKa18K/rxXb9XnK+KWLAFPcwQYYm4gY8ql8W+IACAs+vIqVSgeBCr8MBWID7NqOocYRIpvStyeW0OeRwGcV/En6ADGLGCwipuQ7xaj0AVLwZwtExJ646wjUL4DcGFBvA/ch8V0gYs9t7wUiOFgLkQguAhHY+LPWABxVOvT7YmyRCA4CEZj4sxeBu6LSkev3INCeZcaBJRBBWYQSOwFHiwVo3xspVTrMJJh/G8cQibB16LqEIXResAQiqPGLnADUP/PnyvV9AADnFxconbkxSTCNqj//MFKlAwCvM5kSv+CcgNZJaK2PUAO/4D4KWiXBpc7h6stXHLhUOkLPD1rhF5xHAXYSsBaktk7d0IzIFb+YYgJqJsFV+DGt4pj6BFT4BfcEcE5CiI8p4Be7kgDqJMT6f274lnIOfokdgO8BSW0SMIyTQAQFfjGFUdBCJIKLQAQ1fsE1ARyS0FwfoQJ+wX0UcBGJSPGPOfVT4xdTSUDtJOi/FppyTld/HsaLIhT4BedRgJ2EkhFY+9ha+CehD9AyCbuOvwtEIDyQafXcA8NET0L+QmwzDNZtlDMPNn7ngyBbo2LKidVLEcpyfrm7RCxBN6xfDXddg6ke+NTALzGJqDEF+sjeB7EIbPwSy/muJQFLLEONvtX9/Yxjz0BfBEZYjlhDa4GNohkAq/pLrsUutbKcRDyt16jrANcCDzPptfDLGpVsCh1gJsAnmlD7flxXEqn1XKAUv8RwHrOPKgG+bSUx6DoJpo+QYIT+ffUU7mG1YolfYjunGA2hBLi2YzyKBb8IxKsefgqdAkr8srT6TYsZDSXkm4RbjgGoI1jhEoxA0Smgwm++nextDTMXg3oClSCBKzjfsTkLohxSOYpG5LSGYeL3FoAtEHUSVwC+4ELH7qPl9gdQ2X8DAKEhOt9O4Sj/AAAAAElFTkSuQmCC');
opacity: 0.75;
z-index: 101;
right: 0;
bottom: 0;
background-size: 256px 262px;
background-position: -64px -198px;
will-change: background-position;
animation-name: float;
animation-timing-function: step-end, step-end;
animation-fill-mode: forwards;
animation-duration: 5s;

-webkit-animation-name: float;
-webkit-animation-timing-function: step-end, step-end;
-webkit-animation-fill-mode: forwards;
-webkit-animation-duration: 5s;

-ms-animation-name: float;
-ms-animation-timing-function: step-end, step-end;
-ms-animation-fill-mode: forwards;
-ms-animation-duration: 5s;

}


@keyframes float {
0% {
background-position: -128px -131px
}
10% {
background-position: -192px -131px
}
12.5% {
background-position: -128px -131px
}
15% {
background-position: -64px -131px
}
17.5% {
background-position: 0 -133px
}
20% {
background-position: 0 -133px
}
22.5% {
background-position: -192px -131px
}
25% {
background-position: -128px -131px
}
27.5% {
background-position: -64px -131px
}
30% {
background-position: 0 -133px
}
32.5% {
background-position: 0 -133px
}
35% {
background-position: -192px -131px
}
37.5% {
background-position: -128px -131px
}
40% {
background-position: -64px -131px
}
42.5% {
background-position: 0 -133px
}
45% {
background-position: 0 -133px
}
47.5% {
background-position: -192px -131px
}
50% {
background-position: -128px -131px
}
52.5% {
background-position: -64px -131px
}
55% {
background-position: 0 -133px
}
57.5% {
background-position: 0 -133px
}
60% {
background-position: -192px -131px
}
62.5% {
background-position: -128px -131px
}
65% {
background-position: 0 -2px
}
67.5% {
background-position: -192px 1px
}
70% {
background-position: -192px 1px
}
72.5% {
background-position: -128px 2px
}
75% {
background-position: -128px -131px
}
77.5% {
background-position: -64px -131px
}
80% {
background-position: -192px 1px
}
82.5% {
background-position: -192px 1px
}
85% {
background-position: -128px 2px
}
87.5% {
background-position: -64px 2px
}
90% {
background-position: 0 -2px
}
92.5% {
background-position: -192px 1px
}
95% {
background-position: -192px 1px
}
97.5% {
background-position: -128px 2px
}
100% {
background-position: -128px -131px
}
}

@-webkit-keyframes float {
0% {
background-position: -128px -131px
}
2.5% {
background-position: -64px -131px
}
5% {
background-position: 0 -133px
}
7.5% {
background-position: 0 -133px
}
10% {
background-position: -192px -131px
}
12.5% {
background-position: -128px -131px
}
15% {
background-position: -64px -131px
}
17.5% {
background-position: 0 -133px
}
20% {
background-position: 0 -133px
}
22.5% {
background-position: -192px -131px
}
25% {
background-position: -128px -131px
}
27.5% {
background-position: -64px -131px
}
30% {
background-position: 0 -133px
}
32.5% {
background-position: 0 -133px
}
35% {
background-position: -192px -131px
}
37.5% {
background-position: -128px -131px
}
40% {
background-position: -64px -131px
}
42.5% {
background-position: 0 -133px
}
45% {
background-position: 0 -133px
}
47.5% {
background-position: -192px -131px
}
50% {
background-position: -128px -131px
}
52.5% {
background-position: -64px -131px
}
55% {
background-position: 0 -133px
}
57.5% {
background-position: 0 -133px
}
60% {
background-position: -192px -131px
}
62.5% {
background-position: -128px -131px
}
65% {
background-position: 0 -2px
}
67.5% {
background-position: -192px 1px
}
70% {
background-position: -192px 1px
}
72.5% {
background-position: -128px 2px
}
75% {
background-position: -128px -131px
}
77.5% {
background-position: -64px -131px
}
80% {
background-position: -192px 1px
}
82.5% {
background-position: -192px 1px
}
85% {
background-position: -128px 2px
}
87.5% {
background-position: -64px 2px
}
90% {
background-position: 0 -2px
}
92.5% {
background-position: -192px 1px
}
95% {
background-position: -192px 1px
}
97.5% {
background-position: -128px 2px
}
100% {
background-position: -128px -131px
}
}

@-ms-keyframes float {
0% {
background-position: -128px -131px
}
2.5% {
background-position: -64px -131px
}
5% {
background-position: 0 -133px
}
7.5% {
background-position: 0 -133px
}
10% {
background-position: -192px -131px
}
12.5% {
background-position: -128px -131px
}
15% {
background-position: -64px -131px
}
17.5% {
background-position: 0 -133px
}
20% {
background-position: 0 -133px
}
22.5% {
background-position: -192px -131px
}
25% {
background-position: -128px -131px
}
27.5% {
background-position: -64px -131px
}
30% {
background-position: 0 -133px
}
32.5% {
background-position: 0 -133px
}
35% {
background-position: -192px -131px
}
37.5% {
background-position: -128px -131px
}
40% {
background-position: -64px -131px
}
42.5% {
background-position: 0 -133px
}
45% {
background-position: 0 -133px
}
47.5% {
background-position: -192px -131px
}
50% {
background-position: -128px -131px
}
52.5% {
background-position: -64px -131px
}
55% {
background-position: 0 -133px
}
57.5% {
background-position: 0 -133px
}
60% {
background-position: -192px -131px
}
62.5% {
background-position: -128px -131px
}
65% {
background-position: 0 -2px
}
67.5% {
background-position: -192px 1px
}
70% {
background-position: -192px 1px
}
72.5% {
background-position: -128px 2px
}
75% {
background-position: -128px -131px
}
77.5% {
background-position: -64px -131px
}
80% {
background-position: -192px 1px
}
82.5% {
background-position: -192px 1px
}
85% {
background-position: -128px 2px
}
87.5% {
background-position: -64px 2px
}
90% {
background-position: 0 -2px
}
92.5% {
background-position: -192px 1px
}
95% {
background-position: -192px 1px
}
97.5% {
background-position: -128px 2px
}
100% {
background-position: -128px -131px
}
}
<div class="ghost">

</div>

任何指导都会有所帮助。

谢谢。

最佳答案

我尝试了各种方法,但 IE11 是一个棘手的野兽。我发现最好的方法是创建各种类,然后使用 JavaScript 计时器循环遍历它们。我做了类似以下的事情(我使用了 jQuery,但我不必这样做):

.ghost.step1 { background-position: x y }
.ghost.step2 { background-position: x (y+5) }
.ghost.step3 { background-position: (x+5) (y+10) }
.ghost.step4 { background-position: (x+10) (y+15) }
...
.ghost.step40 { background-position: x y }

var num = 1;
var gInterval = setInterval(function(){

if (num == 40) { //max 40 steps

clearInterval(gInterval);
//what do with ghosts after?

} else {

$ghosts.removeClass('step'+(num-1)).addClass('step'+num);
num++;

}

}, 250);

这不是一个好的解决方案,也没有利用 CSS3 的功能,但 IE 什么时候让这一切变得如此简单?

关于IE11中的CSS动画背景-位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57029584/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com