【发布时间】:2026-01-08 03:50:01
【问题描述】:
我想删除、更改第二行的颜色或更改第二行的位置。
另外,有没有办法使已经创建的线条的颜色不同?
var cvs = document.querySelector('#canvas')
var ctx = cvs.getContext('2d')
cvs.height = window.innerHeight - 40
cvs.width = window.innerWidth - 40
window.addEventListener('resize', () => {
cvs.height = window.innerHeight - 40;
cvs.width = window.innerWidth - 40;
})
ctx.beginPath();
ctx.strokeStyle = 'red'
ctx.lineWidth = '5'
ctx.lineCap = 'round'
ctx.moveTo(200, 600)
ctx.lineto(100,100)
ctx.closePath();
//Second path which is what i want to remove only
ctx.beginPath();
ctx.strokeStyle = 'blue'
ctx.lineWidth = '37px'
ctx.moveTo(100,100)
ctx.lineTo(300, 500)
ctx.stroke()
ctx.closePath()
【问题讨论】:
标签: javascript html canvas path