【发布时间】:2020-11-15 12:47:51
【问题描述】:
这是我第一次发布问题。如果我不了解所有礼仪,请保持冷静。我正在使用内置 SVGator 的 SVG 动画。我正在将它作为加载页面加载到我的 react 应用程序中。
SVG 文件本身在浏览器中显示正常,但是当我将它加载到我的 React 应用程序时,我收到了错误:
Failed to compile.
./src/assets/Loadingpage.svg (./node_modules/@svgr/webpack/lib?-svgo,+titleProp,+ref!./src/assets/Loadingpage.svg)
Error: Expected node, got `#eba7ha49d1l68_to {animation: eba7ha49d1l68_to__to 3000ms linear infinite normal forwards}@keyframes eba7ha49d1l68_to__to { 0% {transform: translate(0px,0px);animation-timing-function: cubic-bezier(0.420000,0,1,1)} 16.666667% {transform: translate(0px,-50px)} 33.333333% {transform: translate(0px,-100px)} 100% {transform: translate(0px,-100px)} }#eba7ha49d1l68 {animation: eba7ha49d1l68_c_o 3000ms linear infinite normal forwards}@keyframes eba7ha49d1l68_c_o { 0% {opacity: 0;animation-timing-function: cubic-bezier(0.420000,0,1,1)} 23.333333% {opacity: 1} 33.333333% {opacity: 0} 100% {opacity: 0} }#eba7ha49d1l69_to {animation: eba7ha49d1l69_to__to 3000ms linear infinite normal forwards}@keyframes eba7ha49d1l69_to__to { 0% {transform: translate(0px,0px)} 40% {transform: translate(0px,0px);animation-timing-function: cubic-bezier(0.420000,0,1,1)} 56.666667% {transform: translate(0px,-50.003000px)} 73.333333% {transform: translate(0px,-100.003000px)} 100% {transform: translate(0px,-100.003000px)} }#eba7ha49d1l69 {animation: eba7ha49d1l69_c_o 3000ms linear infinite normal forwards}@keyframes eba7ha49d1l69_c_o { 0% {opacity: 0} 40% {opacity: 0;animation-timing-function: cubic-bezier(0.420000,0,1,1)} 63.333333% {opacity: 1} 73.333333% {opacity: 0} 100% {opacity: 0} }`
这将我指向文件顶部的这个 CDATA:
<style>
<![CDATA[#eba7ha49d1l68_to {
animation: eba7ha49d1l68_to__to 3000ms linear infinite normal forwards
}
@keyframes eba7ha49d1l68_to__to {
0% {
transform: translate(0px, 0px);
animation-timing-function: cubic-bezier(0.420000, 0, 1, 1)
}
16.666667% {
transform: translate(0px, -50px)
}
33.333333% {
transform: translate(0px, -100px)
}
100% {
transform: translate(0px, -100px)
}
}
#eba7ha49d1l68 {
animation: eba7ha49d1l68_c_o 3000ms linear infinite normal forwards
}
@keyframes eba7ha49d1l68_c_o {
0% {
opacity: 0;
animation-timing-function: cubic-bezier(0.420000, 0, 1, 1)
}
23.333333% {
opacity: 1
}
33.333333% {
opacity: 0
}
100% {
opacity: 0
}
}
#eba7ha49d1l69_to {
animation: eba7ha49d1l69_to__to 3000ms linear infinite normal forwards
}
@keyframes eba7ha49d1l69_to__to {
0% {
transform: translate(0px, 0px)
}
40% {
transform: translate(0px, 0px);
animation-timing-function: cubic-bezier(0.420000, 0, 1, 1)
}
56.666667% {
transform: translate(0px, -50.003000px)
}
73.333333% {
transform: translate(0px, -100.003000px)
}
100% {
transform: translate(0px, -100.003000px)
}
}
#eba7ha49d1l69 {
animation: eba7ha49d1l69_c_o 3000ms linear infinite normal forwards
}
@keyframes eba7ha49d1l69_c_o {
0% {
opacity: 0
}
40% {
opacity: 0;
animation-timing-function: cubic-bezier(0.420000, 0, 1, 1)
}
63.333333% {
opacity: 1
}
73.333333% {
opacity: 0
}
100% {
opacity: 0
}
}
]]>
</style>
当我将其注释掉时,它似乎修复了我整个文档中其余的 <rect> 和 <path> 标记,并且我的应用程序可以正常编译。当我在我的应用程序中将 SVG 作为加载页面点击时,它显示正常,但动画不起作用。
我对使用 SVG 非常陌生,而 CDATA 对我来说是 100% 的新手。任何帮助将不胜感激。谢谢!
编辑:我仍然不确定为什么,但删除包装 标记并保持 CSS 样式解决了我的问题。
【问题讨论】:
标签: reactjs animation svg cdata svgator