简体   繁体   English

Chrome CSS动画背景图片问题

[英]Chrome CSS background-image problems with animation

Here is the link to code https://jsfiddle.net/pk7zetdu/6/ 这是代码https://jsfiddle.net/pk7zetdu/6/的链接

$('.img_cont').addClass('rollIn');

  setTimeout(function(){
    $('.img_cont').removeClass('rollIn').addClass('rollOut');
  }, 3000);

  setTimeout(function(){
    $('#img_img').attr('src', 'http://www.hercampus.com/sites/default/files/2013/02/27/topic-1350661050.jpg');
    $('.img_co....

Try to open it with latest stable chrome for windows. 尝试使用适用于Windows的最新稳定铬打开它。

First when it loads, you can see the slide (div) rolling in and rolling out, than image SRC is changed and div rolls in for the second time with new bg (maybe with a small img loading delay). 首先,在加载时,您会看到幻灯片(div)滚入和滚出,然后更改了图像SRC并第二次使用新的bg(可能具有较小的img加载延迟)再次滚动div。 All fine! 一切都很好!

Then please press RUN button in fiddle and watch again. 然后请按小提琴中的“运行”按钮,然后再次观看。 You now can see the slide (div) rolling in and rolling out, than image SRC is changed, but it rolls in with previous image in bg and changes it right after the animation is complete. 现在,您可以看到幻灯片(div)滚入和滚出,而不是图像SRC被更改,但是它与bg中的前一个图像一起进入,并在动画完成后立即对其进行更改。

I can ensure you this has nothing to do with Image loading or fiddle it self, because it's a big problem in my real project. 我可以确保您这与图像加载无关,也可以自行调整图像,因为这在我的实际项目中是个大问题。 -webkit-backface-visibility: hidden; -webkit-backface-visibility:隐藏; on IMG solves the issue, but introduces to other problems in more serious examples :(. 在IMG上解决了该问题,但在更严重的示例中介绍了其他问题:(。

Any ideas? 有任何想法吗?

================ UPDATE ================更新

When I change .rollOut opacity to something not zero ( https://jsfiddle.net/pk7zetdu/8/ ), the problem is gone. 当我将.rollOut的不透明度更改为非零值( https://jsfiddle.net/pk7zetdu/8/ )时,问题就消失了。 Seems that when opacity of img parent is 0, chrome does not adjust new SRC, and has problems to adjust it while in animation. 似乎当img父级的不透明度为0时,chrome无法调整新的SRC,并且在动画时无法调整它。

Your second image has a shadow around all its sides. 您的第二张图片四周都有阴影。 You can see that if you open the image in a tab(you will see that the image has some gap from top and left). 您可以看到,如果在选项卡中打开图像(您将看到图像顶部和左侧之间有一定的间隙)。 So your second image doesnt load with the first image in background. 因此,您的第二张图像不会与背景中的第一张图像一起加载。 Its just the second image that has the white gap around it. 它只是第二个图像,周围有白色缝隙。

Changing the images will do the trick. 更改图像将达到目的。 Check this fiddle with different images. 用不同的图像检查这个小提琴。 - https://jsfiddle.net/pk7zetdu/11/ -https://jsfiddle.net/pk7zetdu/11/

As for the second image not rolling out after 3 seconds, you can change the setTimeout to setInterval 至于第二张图片在3秒后仍未推出,您可以将setTimeout更改为setInterval

This was Chrome March built bug. 这是Chrome March内置的错误。 It's fixed in newest version. 最新版本已修复。 Anyway (if you care about march version) a quick fix is to set Opacity to something like 0.0001 instead of 0, when fading out. 无论如何(如果您在乎行军版本),一个快速的解决方法是在淡出时将不透明度设置为0.0001而不是0。 There is no good solution. 没有好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM