【发布时间】:2021-11-22 23:25:23
【问题描述】:
对不起,我的英语很差,我会尽量描述我最需要的东西。 jsFiddle 将帮助您了解我想要什么:https://jsfiddle.net/8natrpqm/
var circle = document.querySelector('.animated-circle--animated > .animated-circle__circle');
var ghostCircle = document.querySelector('.animated-circle--animated > .animated-circle__circle--ghost');
var radius = circle.r.baseVal.value;
var circumference = radius * 2 * Math.PI;
circle.style.strokeDasharray = `${circumference} ${circumference}`;
circle.style.strokeDashoffset = `${circumference}`;
ghostCircle.style.strokeDasharray = `${circumference} ${circumference}`;
ghostCircle.style.strokeDashoffset = `${circumference}`;
function setProgress(percent) {
const offset = circumference - percent / 100 * circumference;
circle.style.strokeDashoffset = offset;
}
function setGhostProgress(percent) {
const offset = circumference - percent / 100 * circumference;
ghostCircle.style.strokeDashoffset = offset;
}
var progress = 0;
var ghostProgress = 0;
function animateProgress() {
if (progress < 18) {
progress++;
setProgress(progress);
setTimeout(animateProgress, 60);
} else {
animateGhostProgress();
}
}
function animateGhostProgress() {
if (ghostProgress < 18) {
ghostProgress++;
setGhostProgress(ghostProgress);
setTimeout(animateGhostProgress, 60);
} else {
}
}
animateProgress();
.circles {
position: relative;
}
.animated-circle--fixed {
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
.animated-circle--animated {
position: relative;
z-index: 50;
}
.animated-circle__circle {
transition: 0.35s stroke-dashoffset;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
.animated-circle__circle--ghost {
z-index: 60;
}
<div class="circles">
<svg class="animated-circle animated-circle--fixed" width="400" height="400">
<circle class="animated-circle__circle" stroke="lightblue" stroke-width="2" fill="transparent" r="199" cx="200" cy="200" />
</svg>
<svg class="animated-circle animated-circle--animated" width="400" height="400">
<circle class="animated-circle__circle" stroke="blue" stroke-width="2" fill="transparent" r="199" cx="200" cy="200" />
<circle class="animated-circle__circle animated-circle__circle--ghost" stroke="lightblue" stroke-width="2" fill="transparent" r="199" cx="200" cy="200" />
<circle class="circle-icon__circle" stroke="transparent" stroke-width="0" fill="red" r="15" cx="375" cy="110" />
</svg>
</div>
我想为 SVG 圆的边界设置动画,以某种方式直到一个点,然后也逐渐消失。我正在使用 stroke-dashoffset,从 0 到 15 可以正常工作,但我真的找不到相反的方法(意味着 15 保持在上,但下必须再次向上移动到 0 到 15 )。
在 Fiddle 中,您会看到我尝试添加一个幽灵圆圈来与第一个动画圆圈重叠,但结果有点奇怪,就像存在图形问题一样。
有什么想法吗?
谢谢!
【问题讨论】:
标签: javascript css svg