ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## Canvas动画 ~~~ var posx = 0; var posy = 0; var dir = 1; var isMouseInRect = false; canvas.onmousemove = function(e) { console.log(e); var mouseX = e.offsetX; var mouseY = e.offsetY; if(mouseX > posx && mouseX < posx + 50 && mouseY > posy && mouseY < posy + 50) { isMouseInRect = true; } else { isMouseInRect = false; } } setInterval(function(){ if(!isMouseInRect) { posx += 10 * dir; } //清空画布的矩形区域 ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.fillRect(posx, posy, 50, 50); if(posx + 50>= canvas.width) { dir = -1; } else if(posx <= 0) { dir = 1; } },100) ~~~