Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda