Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Drawig disappears on canvas on mouseup : Fabric JS : ctx

I have made a canvas with Fabric JS. I loaded an image on canvas with Fabric Js. Now, I want to do some drawing with using ctx object. I can successfully draw on canvas, but when ever I leaves the mouse, all drawing disappears.

Here is the code:

let el = document.getElementById('canvas');
let ctx = el.getContext('2d');
// canvas variable is Fabric JS canvas.

function simpleDraw() {
    let isDrawing;
    canvas.on('mouse:down', function (o) {
        let p1 = canvas.getPointer(o.e);
        isDrawing = true;
        ctx.lineWidth = 10;
        ctx.lineJoin = ctx.lineCap = 'round';
        ctx.moveTo(p1.x, p1.y);
   });

   canvas.on('mouse:move', function (o) {
      let p2 = canvas.getPointer(o.e);
      if (isDrawing) {
          ctx.lineTo(p2.x, p2.y);
          ctx.stroke();
      }
   });

  canvas.on('mouse:up', function (o) {
      isDrawing = false;
      canvas.requestRenderAll();
  });

}

I have to do drawing with ctx only, beacause I have to do some animation stuff. I cannot use Fabric JS freeDrawingBrush.

Here is problem video link

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!