我正在嘗試animate
幾個paths
在svg
約兩個circles
。我的目標是以scale
爲中心的paths
,就好像它們在搏動一樣。我已經看過每一個在stackoverflow上的答案來弄清楚如何實現這一點。 The closest solution我發現沒有炒鍋。在中心點的Svg刻度路徑(搏動)
這是我到目前爲止的jsfiddle。如您所見,paths
正在縮小/朝向原點。如果沒有辦法通過CSS
來實現這個目標,是否有可能通過javascript
這樣的框架來實現呢?Velocity.js
?
這是SVG:
<div class="wrapper">
<svg version="1.1" viewBox="20 20 60 60" >
<g class="icon-sun">
<path class="icon-sun-beam"
d="M64.175,38.688c-0.781,0.781-2.049,0.781-2.828,0c-0.781-0.781-0.781-2.047,0-2.828l2.828-2.828c0.779-0.781,2.047-0.781,2.828,0c0.779,0.781,0.779,2.047,0,2.828L64.175,38.688z"/>
<path class="icon-sun-beam"
d="M64.175,38.688c-0.781,0.781-2.049,0.781-2.828,0c-0.781-0.781-0.781-2.047,0-2.828l2.828-2.828c0.779-0.781,2.047-0.781,2.828,0c0.779,0.781,0.779,2.047,0,2.828L64.175,38.688z"/>
<path class="icon-sun-beam"
d="M50.034,34.002c-1.105,0-2-0.896-2-2v-3.999c0-1.104,0.895-2,2-2c1.104,0,2,0.896,2,2v3.999C52.034,33.106,51.136,34.002,50.034,34.002z"/>
<path class="icon-sun-beam"
d="M35.893,38.688l-2.827-2.828c-0.781-0.781-0.781-2.047,0-2.828c0.78-0.781,2.047-0.781,2.827,0l2.827,2.828c0.781,0.781,0.781,2.047,0,2.828C37.94,39.469,36.674,39.469,35.893,38.688z"/>
<path class="icon-sun-beam"
d="M34.034,50c0,1.104-0.896,1.999-2,1.999h-4c-1.104,0-1.998-0.896-1.998-1.999s0.896-2,1.998-2h4C33.14,48,34.034,48.896,34.034,50z"/>
<path class="icon-sun-beam"
d="M35.893,61.312c0.781-0.78,2.048-0.78,2.827,0c0.781,0.78,0.781,2.047,0,2.828l-2.827,2.827c-0.78,0.781-2.047,0.781-2.827,0c-0.781-0.78-0.781-2.047,0-2.827L35.893,61.312z"/>
<path class="icon-sun-beam"
d="M50.034,65.998c1.104,0,2,0.895,2,1.999v4c0,1.104-0.896,2-2,2c-1.105,0-2-0.896-2-2v-4C48.034,66.893,48.929,65.998,50.034,65.998z"/>
<path class="icon-sun-beam"
d="M64.175,61.312l2.828,2.828c0.779,0.78,0.779,2.047,0,2.827c-0.781,0.781-2.049,0.781-2.828,0l-2.828-2.827c-0.781-0.781-0.781-2.048,0-2.828C62.126,60.531,63.392,60.531,64.175,61.312z"/>
<circle class="icon-sun-outline"
cx="50.034"
cy="50"
r="11.999"/>
<circle class="icon-sun-fill"
fill="#FFFFFF"
cx="50.034"
cy="50"
r="7.999"/>
</g>
</svg>
</div>
這裏是CSS:
.wrapper {
width: 100px;
text-align: center;
}
.icon-sun-beam {
animation-name: scale;
animation-duration: 3s;
animation-iteration-count: infinite;
transform-origin: 50px 50px;
animation-timing-function: linear;
animation-fill-mode: both;
animation-direction: alternate;
}
.icon-sun-beam:nth-child(even) {
animation-delay: 4.5s, 4.5s;
}
.icon-sun {
animation-name: rotate;
animation-iteration-count: infinite;
animation-duration: 18s;
animation-timing-function: linear;
transform-origin: 50px 50px;
}
svg {
shape-rendering: geometricPrecision;
}
@keyframes rotate {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
@keyframes scale {
0% {
transform: scale(0.85, 0.85);
}
100% {
transform: scale(1.35, 1.35);
}
}
我有一個很難搞清楚你的意思是什麼,你需要什麼幫助。我不明白這是一個顯示你的問題的最小例子。 – Persijn
@Persijn在jsfiddle演示中,您可以看到路徑中定義的形狀在圍繞圓旋轉時的大小縮放。隨着路徑縮放,它們也會離開/接近x/y軸上的圓圈。我試圖讓路徑縮放而不會離開/靠近圓圈。 –
@IgnatOspadov將光線的原點更改爲'transform-origin:50%;'而不是'50px'。儘管在某些瀏覽器中,'%'使用整個畫布的比例。 [錯誤1209061](https://bugzilla.mozilla.org/show_bug.cgi?id=1209061) – Erevald