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

Html – How to get the hyperlink in a tag using javascript?

Here I have an html with javascript: document.addEventListener('mousedown', function(event) { let elem = event.target; let jsonObject = { Key: 'mousedown', Value: event.button }; if (event.button == 2) { console.log(elem.outerHTML); } }); <span style="font-size:xx-large"> <a href="https://microsoft.com" target="_blank" rel="noreferrer noopener" shape="rect" style="color:rgb(17,85,204)">…

VIEW QUESTION
Back To Top
Search