【发布时间】:2022-01-06 06:32:25
【问题描述】:
我的下面的代码会在我启动矩形时为矩形设置动画。我怎样才能让它同时向左生长?我已经尝试过 (line.x -= line.dx) 和其他一些变体,但它似乎不起作用。
const line = {
x: 600,
y: 100,
width: 1,
height: 3,
dx: 1,
dy: 1,
}
let totalLineWidth = line.x + line.width;
const drawLine = () => {
ctx.fillRect(line.x, line.y , line.width, line.height)
}
const update = () => {
drawLine()
line.x += line.dx
requestAnimationFrame(update)
}
update()
【问题讨论】:
标签: css reactjs html5-canvas