简体   繁体   English

Safari 12 css动画效果不佳

[英]Safari 12 css animations not working well

I'm trying to animate a list of elements to slide in one after the other when rendered into the page. 我正在尝试动画一个元素列表,以便在渲染到页面时一个接一个地滑动。

Everything works well in Chrome and Firefox, even in Safari 11 work well, but safari 12 is not doing the animation well. 一切都适用于Chrome和Firefox,即使在Safari 11工作得很好,但safari 12也不能很好地完成动画。

As shown in the following image, all items should be aligned to the top when the animation is completed, but for some reason only in Safari 12, the items are randomly rendered. 如下图所示,当动画完成时,所有项目应与顶部对齐,但由于某些原因,仅在Safari 12中,项目是随机呈现的。 In addition to that, the mouse over on the button is off. 除此之外,按钮上的鼠标已关闭。

在此输入图像描述

You can take a look at the problem here: https://codepen.io/crysfel/pen/GwoQxE (Make sure to open the link with safari 12) 您可以在这里查看问题: https//codepen.io/crysfel/pen/GwoQxE (确保打开safari 12的链接)

I think the css is pretty standard: 我认为css非常标准:

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(60px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.slide-in {
  opacity:0;
  transform: translateY(60px);
  animation: slideIn ease 1;
  animation-fill-mode: forwards;
  animation-duration: 175ms;
}

And a simple javascript to animate the items one after the other: 和一个简单的JavaScript一个接一个地动画项目:

function animateIn() {
  $('ul li').each(function(index) {
    $(this).removeClass('slide-in');
    setTimeout(() => {
      $(this).addClass('slide-in');
    }, 50 * index)
  })
}


$(() => {

  animateIn();

  $('#show').click(function() {
    animateIn();  
  });
});

EDIT: 编辑:

I've fixed the issue : It turns out all I had to do was removing transform: translateY(60px); 我已经解决了这个问题 :事实证明我所要做的就是删除transform: translateY(60px); from slide-in . slide-in Apparently safari was using that style at the end of the animation overwriting the final value. 显然,safari在动画结束时使用该样式覆盖最终值。 It's very weird, because visually looks wrong but the active zones and all are fine. 这很奇怪,因为视觉上看起来不对,但活动区域都很好。

You probably need to add a prefix to keyframes and animation for safari. 您可能需要为关键帧和Safari的动画添加前缀。 Use something like this: 使用这样的东西:

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(60px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@-webkit-keyframes slideIn {
  from {
    opacity: 0;
    -webkit-transform: translateY(60px);
  }
  to {
    opacity: 1;
    -webkit-transform: translateY(0);
  }
}
.slide-in {
  opacity:0;
  transform: translateY(60px);
  -webkit-transform: translateY(60px);
  animation: slideIn ease 1;
  -webskit-animation: slideIn ease 1;
  animation-fill-mode: forwards;
  -webkit-animation-fill-mode: forwards;
  animation-duration: 175ms;
  -webkit-animation-duration: 175ms;
} 

A helpful tool to use is shouldiprefix.com 一个有用的工具是shouldiprefix.com

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

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