问题描述
我在点击时无法清除画布。它似乎包含 requestAnimationFrame 中的值,因此将所有内容放回原处。
我错过了什么?
const canvas = document.querySelector("canvas");
canvas.width = window.innerWidth * 2;
canvas.height = window.innerHeight * 2;
canvas.style.width = window.innerWidth + "px";
canvas.style.height = window.innerHeight + "px";
const ctx = canvas.getContext("2d");
const video = document.querySelector("video");
var myReq;
document.addEventListener("click",(event) => {
ctx.clearRect(0,canvas.width,canvas.height);
video.src = event.target.dataset.vid;
window.cancelAnimationFrame(myReq);
console.log("myReq",myReq)
animate(event)
})
document.addEventListener('mousemove',(event) => {
animate(event)
})
function animate(event) {
function step() {
ctx.drawImage(video,event.pageX,event.pageY,660,360)
myReq = window.requestAnimationFrame(step)
}
myReq = window.requestAnimationFrame(step);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)