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

103
Views
Event dispatching in Javascript

I'm trying to puzzle out the event dispatching in Javascript. The example below uses Fabricjs library.

AS IS: if we mouseover the redBox, it becomes black.

TO BE: I'm trying to invoke the redBox mouseover event from greyBox mouseover event. So if we mouseover the greyBox, it must work as if we mousever the redBox. As a result the redBox must become black.

But I don't understand what to write instead of interrogation mark.

var greyBox = new fabric.Rect({
    fill: 'grey',
    width: 100,
    height: 100
});

var redBox = new fabric.Rect({
    left:300,
    top:300,
    fill: 'red',
    width: 100,
    height: 100
});

function createCanvas(id){
    canvas = new fabric.Canvas(id);
    canvas.add(greyBox);
    canvas.add(redBox);

    redBox.on("mouseover", function(e){
        redBox.set({fill: 'black'});
    })

    greyBox.on("mouseover", function(e){
        // ????
    })

    return canvas;
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You could move the logic to a separate function and invoke it when necessary:

const makeRedBoxBlack = () => redBox.set({fill: 'black'});

redBox.on("mouseover", makeRedBoxBlack);
greyBox.on("mouseover", makeRedBoxBlack);
about 4 years ago · Juan Pablo Isaza Report

0

You only have to add that red box set statement, so it should something like :-

greyBox.on("mouseover", function(e){
        redBox.set({fill: 'black'});
    })
about 4 years ago · Juan Pablo Isaza Report
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!