首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从已经包含动画的文件中呈现和动画SVG

从已经包含动画的文件中呈现和动画SVG
EN

Stack Overflow用户
提问于 2019-02-22 00:34:44
回答 2查看 45关注 0票数 0

我正在开发一个reactjs网络应用程序。我有一个已经包含动画的svg旋转文件。我想知道是否有一种方法可以在矩形上呈现它(包括动画)。我已经在渲染svg图像了,但是当我使用与此相同的clase时,不会呈现任何内容。我想那是因为动画。

有一种方法可以从svg中“提取”动画并将其转换为关键帧

这是svg文件:

代码语言:javascript
复制
<svg width='48px' height='48px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-default">
  <rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(0 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-1s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(25.714285714285715 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.9285714285714286s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(51.42857142857143 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.8571428571428571s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(77.14285714285714 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.7857142857142857s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(102.85714285714286 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.7142857142857143s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(128.57142857142858 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.6428571428571429s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(154.28571428571428 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.5714285714285714s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(180 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.5s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(205.71428571428572 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.42857142857142855s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(231.42857142857142 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.35714285714285715s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(257.14285714285717 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.2857142857142857s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(282.85714285714283 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.21428571428571427s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(308.57142857142856 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.14285714285714285s' repeatCount='indefinite'/>
  </rect>
  <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(334.2857142857143 50 50) translate(0 -30)'>
    <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-0.07142857142857142s' repeatCount='indefinite'/>
  </rect>
</svg>

非常感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-22 11:36:16

我不确定我是否遵循了您所说的“提取”的意思,但note支持SVG:

定义:

代码语言:javascript
复制
const Spinner = () => (
  <svg width='48px' height='48px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" className="uil-default">
    <rect x="0" y="0" width="100" height="100" fill="none" className ="bk" />
    <rect  x='47' y='40' width='6' height='20' rx='3' ry='3' fill='#000000' transform='rotate(0 50 50) translate(0 -30)'>
      <animate attributeName='opacity' from='1' to='0' dur='1s' begin='-1s' repeatCount='indefinite'/>
    </rect>
  ...
  </svg>);

然后在您的React应用程序中这样使用:

代码语言:javascript
复制
<Spinner />
票数 2
EN

Stack Overflow用户

发布于 2019-02-22 11:35:19

这里有一个简单的css解决方案,可能对您有用。

这个解决方案是从正在加载中提取的。

代码语言:javascript
复制
.lds-spinner {
  color: official;
  display: inline-block;
  position: relative;
  width: 64px;
  height: 64px;
}
.lds-spinner div {
  transform-origin: 32px 32px;
  animation: lds-spinner 1.2s linear infinite;
}
.lds-spinner div:after {
  content: " ";
  display: block;
  position: absolute;
  top: 3px;
  left: 29px;
  width: 5px;
  height: 14px;
  border-radius: 20%;
  background: black;
}
.lds-spinner div:nth-child(1) {
  transform: rotate(0deg);
  animation-delay: -1.1s;
}
.lds-spinner div:nth-child(2) {
  transform: rotate(30deg);
  animation-delay: -1s;
}
.lds-spinner div:nth-child(3) {
  transform: rotate(60deg);
  animation-delay: -0.9s;
}
.lds-spinner div:nth-child(4) {
  transform: rotate(90deg);
  animation-delay: -0.8s;
}
.lds-spinner div:nth-child(5) {
  transform: rotate(120deg);
  animation-delay: -0.7s;
}
.lds-spinner div:nth-child(6) {
  transform: rotate(150deg);
  animation-delay: -0.6s;
}
.lds-spinner div:nth-child(7) {
  transform: rotate(180deg);
  animation-delay: -0.5s;
}
.lds-spinner div:nth-child(8) {
  transform: rotate(210deg);
  animation-delay: -0.4s;
}
.lds-spinner div:nth-child(9) {
  transform: rotate(240deg);
  animation-delay: -0.3s;
}
.lds-spinner div:nth-child(10) {
  transform: rotate(270deg);
  animation-delay: -0.2s;
}
.lds-spinner div:nth-child(11) {
  transform: rotate(300deg);
  animation-delay: -0.1s;
}
.lds-spinner div:nth-child(12) {
  transform: rotate(330deg);
  animation-delay: 0s;
}
@keyframes lds-spinner {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
代码语言:javascript
复制
<div class="lds-spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54818320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档