skip to Main Content

Javascript – How to convert mouse position to canvas coordinate using object-fit: contain

Using object-fit: contain allow to resize a canvas to fit inside a container. This snippet is drawing a circle using mouse event position : canvas.width=1920; canvas.height=1200; const ctx=canvas.getContext("2d"); ctx.lineWidth = 10; ctx.strokeRect(0,0,canvas.width,canvas.height); canvas.onmousemove = (e) => { ctx.clearRect(0,0,canvas.width,canvas.height); ctx.strokeRect(0,0,canvas.width,canvas.height); ctx.beginPath();…

VIEW QUESTION
Back To Top
Search