【发布时间】:2022-02-15 22:50:03
【问题描述】:
我正在尝试使用 CSS 或 SVG 为进度条模拟此动画 有什么方法可以制作这个动画?
我将字符串添加为嵌入式代码,我尝试使用 SVG 而不是 CSS,此图像取自设计师发送的视频
我为尝试应用动画而编写的当前代码示例
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
centerX = canvas.width / 2,
centerY = canvas.height / 2,
rad = (Math.PI * 2) / 50,
speed = 1;
function blueCircle(speed) {
context.save();
context.beginPath();
context.strokeStyle = "#ffffff";
context.lineWidth = 4;
context.arc(
centerX,
centerY,
40,
-Math.PI / 2,
-Math.PI / 2 + speed * rad,
false
);
context.stroke();
context.restore();
}
function reblueCircle(speed) {
context.save();
context.beginPath();
context.strokeStyle = "#ffffff69";
context.lineWidth = 4;
context.arc(
centerX,
centerY,
40,
-Math.PI / 2,
-Math.PI / 2 + speed * rad,
false
);
context.stroke();
context.restore();
}
function whiteCircle() {
context.save();
context.beginPath();
context.strokeStyle = "#ffffff69";
context.lineWidth = 4;
context.arc(centerX, centerY, 40, 0, Math.PI * 2, false);
context.stroke();
context.closePath();
context.restore();
}
var res = false;
(function drawFrame() {
window.requestAnimationFrame(drawFrame, canvas);
context.clearRect(0, 0, canvas.width, canvas.height);
whiteCircle();
blueCircle(speed);
if (res) {
speed -= 0.1;
reblueCircle(speed);
}
if (speed > 50 && !res) {
res = true;
} else if (speed < 50 && !res) {
speed += 0.1;
} else if (speed > 50 && !res) {
res = true;
}
})();
body {
background: #000;
}
<canvas id="canvas" width="84" height="84"></canvas>
【问题讨论】:
标签: javascript css svg