プログレスバーに似たサークルをアニメーション化しようとしています。私は次のスライドがいつ来るかを追跡するためにカルーセルでそれを使用するつもりです。私が抱えている問題は、アニメーションの時間を変更する方法がわからないことです。私はフレームレートを調整しようとしましたが、それは動作しますが、アニメーションは本当に不安定になります。 setIntervalの種類の作品が、私は意図しているように、その一部だけではなく、サークル全体を表示するので、適切に時間を設定することはできません。アニメーションの速度を制御できるようにする必要があります。アニメーションの速度を遅くする必要はありません。私が取り組んでいるコードは以下の通りです。リクエストアニメーションフレームでのキャンバスアニメーションの継続時間の変更
<script>
(function() {
var requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;
window.requestAnimationFrame = requestAnimationFrame;
})();
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var centerX = canvas.width/2;
var centerY = canvas.height/2;
var radius = 90;
var endPercent = 85;
var curPerc = 0;
var circ = -Math.PI;
var quart = -(Math.PI * 2) + 1;
function animate(current) {
context.clearRect(0, 0, canvas.width, canvas.height);
context.beginPath();
context.arc(centerX, centerY, radius, -(quart), ((circ) * current) - quart, true);
context.lineWidth = 3;
context.strokeStyle = '#000';
context.stroke();
curPerc++;
if (curPerc < endPercent) {
requestAnimationFrame(function() {
animate(curPerc/100)
});
}
}
animate();
</script>
[良い記事](https://www.viget.com/articles/time-based-animation)と[githubの要旨](HTTPSで://要旨。 github.com/greypants/3739036)を時間ベースのキャンバスアニメーションで表示します。 –