简体   繁体   English

CSS旋转动画上的像素跳跃

[英]Pixel jump on CSS Rotate animation

So I've been trying this form challenge involving using no JS for interactive elements and I decided to make it 'fancy'. 因此,我一直在尝试使用不使用JS进行交互元素的表单挑战,因此我决定将其“花哨”。 On click, the form drops and the arrow rotates; 单击时,表格会掉落,箭头旋转; however, you can notice a jump in the pixels. 但是,您会注意到像素的跳跃。 I've viewed the box model several times and all of the pixels add up - I have no idea where this jump comes from. 我已经看过几次盒子模型,所有像素加起来-我不知道这种跳跃的来源。 The only way to stop it is to make the arrow absolute, but it still isn't making sense why exactly that's happening if there's no shift in the layout. 停止它的唯一方法是使箭头变为绝对,但如果布局没有变化,为什么仍会发生这种情况仍然没有意义。 Any ideas? 有任何想法吗?

https://codepen.io/mtbroomell/pen/zeMYdb https://codepen.io/mtbroomell/pen/zeMYdb

.ins {
  display: block;
  text-shadow: 
    20px 0 0 rgba(255,0,0,.6), 
    -20px 0 0 rgba(0,255,0,.6), 
    0 20px 0 rgba(0,0,255,.6);
  font-size: 200px;
  line-height:1;
  color: transparent;
  transform: rotate(0deg);
  transition: .5s;
}
.form-toggle:checked ~ .ins-wrap .ins {
    text-shadow: 
    0 0 0 rgba(0,0,0,.5), 
    0 0 0 rgba(0,0,0,.5), 
    0 0 0 rgba(0,0,0,.5);
    transition: .5s;
    transform: rotate(90deg);
}

^^^ The above is some of the sample styling as I'm not allowed to post CodePen without code. ^^^上面是一些示例样式,因为我不允许发布没有代码的CodePen。

I'm not sure what the native frame rate for css animations is but it's not fast enough. 我不确定CSS动画的本机帧速率是多少,但是速度不够快。 In animation the minimum frame rate needed to create the illusion of seamless movement is 24 fps. 在动画中,产生无缝运动错觉所需的最小帧速率为24 fps。 Using a requestanimationframe() would bump it up to 60 but then you'd need JS. 使用requestanimationframe()会将其提高到60,但是您需要JS。 I found this article on medium about CSS smooth animations. 我在有关CSS平滑动画的媒体上找到了这篇文章。 Might help? 可能有帮助? https://medium.com/outsystems-experts/how-to-achieve-60-fps-animations-with-css3-db7b98610108 https://medium.com/outsystems-experts/how-to-achieve-60-fps-animations-with-css3-db7b98610108

I'm going to preface this by saying it seems quite smooth to me on a 2017 Macbook Pro using Chrome 72. 我将通过在使用Chrome 72的2017年Macbook Pro上实现流畅的操作来对此进行开头。

That said, almost all CSS animation jankiness on basic transforms can be improved by tricking the browser into using the GPU thread to render the element instead of the CPU. 也就是说,通过欺骗浏览器使用GPU线程而不是CPU来渲染元素,几乎可以改善基本转换上的所有CSS动画效果。 You can do that by forcing a 3d transform. 您可以通过强制进行3D变换来做到这一点。

.animatedElement {
   transform: translateZ(0);
}

Flickers and jumps in Chrome and FF can often be fixed with backface-visibility and perspective . Chrome和FF中的闪烁和跳跃通常可以通过backface-visibilityperspective backface-visibility来解决。 Remember to use browser prefixes or a build tool that adds them. 记住要使用浏览器前缀或添加前缀的构建工具。

.animatedElement {
  backface-visibility: hidden;
  perspective: 1000;
}

On their own, these don't do anything visually but they trick the browser renderer into doing some additional calculations. 它们本身不会在视觉上做任何事情,但是会诱骗浏览器渲染器进行一些其他计算。

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

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