我在from
范围内有2个选择器to
和@keyframes
,如下所示:
@keyframes pie {
from {
stroke-dashoffset: 0;
}
to {
stroke-dashoffset: 77px;
}
}
我想通过JavaScript更改to
的属性,但是好像给style
赋予.pie
属性并没有达到我的期望。它直接将属性创建为.pie
而不是to
选择器。
这是我到目前为止所做的:
class Timer {
constructor(elem) {
this.elem = document.querySelector(elem);
this.change();
}
change() {
this.elem.style.strokeDashoffset = 10 + 'px';
}
}
let getTimer = new Timer('.pie');
svg.timer {
width: 40px;
height: 40px;
transform: rotateY(-180deg) rotateZ(-90deg);
}
circle {
stroke-dasharray: 77px;
stroke-dashoffset: 0px;
stroke-width: 2px;
stroke: brown;
animation: pie 10s linear infinite forwards;
}
@keyframes pie {
from {
stroke-dashoffset: 0;
}
to {
stroke-dashoffset: 77px;
}
}
<div class="pie">
<svg class="timer">
<circle r="12" cx="20" cy="20">
</circle>
</svg>
</div>
是否有任何方法可以通过JavaScript在attribute
选择器内更改to
?