如何防止Safari浏览器CSS关键帧动画闪烁?

4
I've尝试过添加额外的关键帧(0%,1%,100%或0%,99%,100%),将-webkit-animation-fill-mode设置为向前,以及在其他线程中提到的-webkit-backface-visibility:hidden;技巧,但我仍然在Safari 7(桌面和iOS)的css关键帧动画开始时看到闪烁。 Chrome似乎没有闪烁。
JSBin:http://jsbin.com/julor/2/edit HTML:
<div class="ripple"></div>

CSS:

body {
  background-color: #90CBEA;
}

.ripple, .ripple:before, .ripple:after {
  background-image: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, .15) 100%);

  border-radius: 50%;
  position: absolute;
  top: 50%; left: 50%;
  -webkit-transform: translateX(-50%) translateY(-50%);
}

.ripple:before, .ripple:after {
  content: '';
  display: block; 
}

.ripple {
  -webkit-animation-name: innerRipple;
  -webkit-animation-duration: 3s;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-timing-function: ease-out;

  &:before {
    -webkit-animation-name: ripple;
  -webkit-animation-duration: 3s;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-timing-function: ease-out;
  }

  &:after {
    -webkit-animation-name: outerRipple;
  -webkit-animation-duration: 3s;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-timing-function: ease-out;
  }
}

@-webkit-keyframes innerRipple {
  from {
    height: 0px;
    width: 0px;
    opacity: 1;
  }

  to {
    height: 200px;
    width: 200px;
    opacity: 0;
  }
}

@-webkit-keyframes ripple {
  from {
    height: 0px;
    width: 0px;
    opacity: 1;
  }

  to {
    height: 300px;
    width: 300px;
    opacity: 0;
  }
}

@-webkit-keyframes outerRipple {
  from {
    height: 0px;
    width: 0px;
    opacity: 1;
  }

  to {
    height: 340px;
    width: 340px;
    opacity: 0;
  }
}
1个回答

5

在Safari浏览器(Safari 8 OS X)中,稍早一些添加帧比在99%处添加帧可以消除闪烁问题!

@-webkit-keyframes innerRipple {
  0% { height: 0px; width: 0px; opacity: 1; }
  95% { height: 200px; width: 200px; opacity: 0; }
  100% { width: 0px; height: 0px; opacity: 0; }
}

@-webkit-keyframes ripple {
  0% { height: 0px; width: 0px; opacity: 1; }
  95% { height: 300px; width: 300px; opacity: 0; }
  100% { width: 0px; height: 0px; opacity: 0; }
}

@-webkit-keyframes outerRipple {
  0% { height: 0px; width: 0px; opacity: 1; }
  95% { height: 340px; width: 340px; opacity: 0; }
  100% { width: 0px; height: 0px; opacity: 0; }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接