简体   繁体   English

Retina显示屏上的CSS3关键帧动画缓慢

[英]CSS3 keyframe animations sluggish on Retina display

Take a very basic CSS3 animation rule like this: 采取一个非常基本的CSS3动画规则,如下所示:

.dimension.fadeIn {
  -webkit-animation: fadeIn 0.7s;
  -webkit-animation-timing-function:ease-in-out;
  height:24px;
}

@-webkit-keyframes fadeIn {
  0% {
    height:0;
    opacity: 0;
  }
  30% {
    height:24px; /* the default row (tr) height */
    opacity: 0;
  }
  90% {
    opacity: 1;
  }
}

In Chrome on every display, except the MacBook Retina display, the animation runs smooth as silk. 除了MacBook Retina显示屏外,在每台显示器的Chrome中,动画都像丝绸一样流畅。 When we try it on a MBP retina, the animation runs visibly slower and generally feels laggy. 当我们在MBP视网膜上进行尝试时,动画运行速度明显变慢,并且通常感觉很迟钝。

I experience the same case when using Transit (if you have a retina and an external display, try running Transit's demos (or any CSS3 animation?), comparing between the two screens and you should feel that it is not as smooth as you'd like) 我在使用Transit时会遇到相同的情况(如果您有视网膜和外部显示器,请尝试运行Transit的演示(或任何CSS3动画?),在两个屏幕之间进行比较,您应该感觉它不像您那样流畅喜欢)

We have tried utilizing the GPU by setting -webkit-transform: translateZ(0) and also some other stuff like -webkit-backface-visibility: hidden but to no avail. 我们尝试通过设置-webkit-transform: translateZ(0)以及其他一些东西来使用GPU,例如-webkit-backface-visibility: hidden但无济于事。

So obviously the Retina display has a higher pixel density, but what approaches can be taken to solve this problem? 显然Retina显示器具有更高的像素密度,但是可以采取什么方法来解决这个问题呢?

Well, first of all, I would change the first height:0; 好吧,首先,我会改变第一个height:0; to height:0px; height:0px; - this can prevent bugs on older browsers. - 这可以防止旧浏览器上的错误。

Second try and add the will-change -property. 第二次尝试添加will-change -property。 This will ease the animation on some browsers, I've experienced. 这将使一些浏览器上的动画变得容易,我经历过。

Besides I find that messing with the height in animations can create a lot of issues. 除此之外我发现搞乱动画中的高度可能会产生很多问题。 I'd rather go with something like: 我宁愿选择以下的东西:

.dimension {
  transition: all .21s ease-in-out;
  will-change: opacity, height;
  height: 0px
}
.dimension.fadeIn {
  -webkit-animation: fadeIn 0.49s;
  -webkit-animation-timing-function:ease-in-out;
  -webkit-animation-delay : .21s;
  height:24px;
}

@-webkit-keyframes fadeIn {
  0% {
    opacity: 0;
  }
  90% {
    opacity: 1;
  }
}

Let me know if it worked :) 让我知道它是否有效:)

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

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