javascript - CSS 动画残留像素碎片

标签 javascript html css animation

我注意到从屏幕的一侧到另一侧的大小和框阴影的简单 CSS 动画后留下的残留像素碎片。

这是 Code Pen 所以你可以看到它的实际效果,它在 Chrome 66 中看起来像这样:

enter image description here

有什么方法可以删除这些剩余的碎片吗?

代码如下:

* {
  
  margin: 0;
  padding: 0;
  box-sizing: content-box;
}

#container {
  
  display: flex;
  align-items: center;
  height: 100vh;
}
  
#box {
    
  position: relative;
  width: 150px;
  height: 150px;
  animation: move 2s infinite alternate ease-in-out;
}

@keyframes move {
  
  0% {
    
    left:  0;
    background-color: blue;
    border-radius: 0;
  }
  
  100% {
    
    left: calc(100vw - 270px);
    background-color: red;
    border-radius: 50%;
    box-shadow:
      0 0 0 20px black,
      0 0 0 40px cyan,
      0 0 0 60px yellow,
      0 0 0 80px pink,
      0 0 0 100px gray,
      0 0 0 120px blue;
  }
}
<div id="container">
  <div id="box">
  </div>
</div>

最佳答案

似乎是在 #box 元素上使用 overflow: hidden; 时消失的呈现错误:

* {
  margin: 0;
  padding: 0;
  box-sizing: content-box;
}

#container {
  display: flex;
  align-items: center;
  height: 100vh;
}

#box {
  overflow: hidden;
  position: relative;
  width: 150px;
  height: 150px;
  animation: move 2s infinite alternate ease-in-out;
}

@keyframes move {
  0% {
    left: 0;
    background-color: blue;
    border-radius: 0;
  }
  100% {
    left: calc(100vw - 250px);
    background-color: red;
    border-radius: 50%;
    box-shadow: 0 0 0 20px black, 0 0 0 40px cyan, 0 0 0 60px yellow, 0 0 0 80px pink, 0 0 0 100px gray, 0 0 0 120px blue;
  }
}
<div id="container">
  <div id="box">
  </div>
</div>

关于javascript - CSS 动画残留像素碎片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50027289/

相关文章:

html - 固定的 Div 溢出不在屏幕上

html - Div 和 anchor 标签之间的随机间距

java - 如何在jsp页面的html标签内放置html标签

javascript - 仅在 X 轴上在 Canvas 上移动图像

javascript - 选择所有不包含特定类的元素

html - iOS 中伪元素双击问题的链接

css - Chrome 中的宋体

javascript - 运行 Google 协作平台小部件的权限问题

javascript - 返回node.js中多个文件的内容

javascript - 在文本表单字段上自动设置光标