【问题标题】:Why are my clip-path scale animations blurry?为什么我的剪辑路径缩放动画模糊?
【发布时间】:2020-05-04 18:46:51
【问题描述】:

我正在开发一个带有全屏加载屏幕的网站,一旦加载了网站中的所有内容,中间的框(其中有一个 SVG clip-path)就会故意变大直到填满整个屏幕。

但是,我试图弄清楚为什么在制作动画时框看起来很模糊。我尝试过所有 GPU 加速方法,包括 transform: translateZ(0)backface-visibilityperspective,但无济于事。

#loading {position:fixed; width:100%; height: 100%; top: 0; left: 0; display: flex; align-items: center; justify-content:center; background: #34d1bf;}
#loading .bar {width: 169px; height: 160px; clip-path: url(#kframe); -webkit-clip-path: url(#kframe); background:#000; overflow: hidden; transform: translateZ(0); animation: loaded 2000ms linear forwards infinite;}

@keyframes loaded {
    0% {transform: scale(1);}
    1% {transform: scale(1);}
    
    32% {transform: scale(1);}
    33% {transform: scale(5);}
    
    65% {transform: scale(5);}
    66% {transform: scale(10);}
    
    99% {transform: scale(10);}
    100% {transform: scale(15);}
}
<div id="loading">
<div class="bar"></div>
</div>

<div style="height: 0; overflow: hidden;">
<svg width="0" height="0" viewBox="0 0 256 256">
<defs>
    <clipPath id="kframe" clipPathUnits="objectBoundingBox">
        <polygon transform="scale(0.00390 0.00390)" points="256,0 0,0 0,72 18,72 18,184 0,184 0,256 222.5,256 256,220 256,36 222.5,36 "/>
    </clipPath>
</defs>
</svg>
</div>

更新:这是一张模糊最明显的一帧照片,在我电脑上的本地版本上进行了测试。经测试,它在 Chrome 和 Safari 上的发生率更高。

【问题讨论】:

  • 很遗憾,我没有看到和/或理解您在制作动画时所说的模糊框是什么意思。你能给我们看一张照片并突出模糊区域吗?
  • @Richard 更新了屏幕截图。显然,我在上面编写的模拟比我本地主机上的类似原始版本运行得更快。

标签: html css svg


【解决方案1】:

您的代码正在剪切 div 元素,然后对其进行缩放。

相反,反过来做。缩放 div 然后剪辑它。一种方法是为 div 的宽度和高度设置动画。

#loading {
  position:fixed;
  width:100%;
  height: 100%;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content:center;
  background: #34d1bf;
}

#loading .bar {
  width: 169px;
  height: 160px;
  clip-path: url(#kframe);
  -webkit-clip-path: url(#kframe);
  background:#000;
  overflow: hidden;
  transform: translateZ(0);
  animation: loaded 2000ms linear forwards infinite;
}

@keyframes loaded {
    0% {width: 169px; height: 160px;}
    1% {width: 169px; height: 160px;}
    
    32% {width: 169px; height: 160px;}
    33% {width: 845px; height: 800px;}
    
    65% {width: 845px; height: 800px;}
    66% {width: 1690px; height: 1600px;}
    
    99% {width: 1690px; height: 1600px;}
    100% {width: 2535px; height: 2400px;}
}
<div id="loading">
<div class="bar"></div>
</div>

<div style="height: 0; overflow: hidden;">
<svg width="0" height="0" viewBox="0 0 256 256">
<defs>
    <clipPath id="kframe" clipPathUnits="objectBoundingBox">
        <polygon transform="scale(0.00390 0.00390)" points="256,0 0,0 0,72 18,72 18,184 0,184 0,256 222.5,256 256,220 256,36 222.5,36 "/>
    </clipPath>
</defs>
</svg>
</div>

【讨论】:

  • 决定给盒子一个百分比宽度和一个百分比底部填充来保持纵横比,一切看起来都应该。但是,我现在需要找到一种方法,使框的宽度和高度能够超出父 #loading 元素的完整宽度和高度范围。
  • overflow:visible 添加到父级应该可以实现这一点。如果它们紧紧包裹父级,您可能还需要将其添加到更高的祖先。
猜你喜欢
  • 2021-11-28
  • 2014-11-12
  • 1970-01-01
  • 2021-10-20
  • 1970-01-01
  • 2014-11-20
  • 2022-01-13
  • 2021-05-01
  • 1970-01-01
相关资源
最近更新 更多