0
我不明白为什么我的代码中的requestAnimationFrame只适用于一个元素。我想这两个动画边框......我在codepen代码 - >http://codepen.io/zey_ser/pen/RPXovp为什么我的多画布动画(requestAnimationFrame)仅适用于一个元素?
<div>
<div id="valueForAnimation" style="display:none;">10</div>
<canvas id="myCanvas" width="100"
height="100"></canvas>
</div>
<div>
<div id="valueForAnimation2" style="display:none;">85</div>
<canvas id="myCanvas2" width="100"
height="100"></canvas>
</div>
<button onclick="stop()">Stop animation</button>
animatedBorders('#myCanvas','valueForAnimation');
animatedBorders('#myCanvas2','valueForAnimation2');
///////////////////////////////////////////////////////////////////////////////////////////////
function animatedBorders (selector,selectorValue){
canvas = document.querySelector(selector);
ctx = canvas.getContext('2d');
...
////////////////////
drawRect();
ID = requestAnimationFrame(animationLoop);
drawText();
////////////////////
function drawRect(){
...
}
function drawLine(){
...
}
function drawText(){
...
}
function animationLoop(){
drawLine();
}
}
之前非常感谢您! –