Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
Attach event listeners to all items on a layer in Paper.js

In jQuery, I can attach an event to all elements like a paragraph, using $("p"). Does something similar exist for Paper.js. I tried using project.activeLayer.children.onMouseEnter but that did not work.

I was thinking about looping over all the children inside the onFrame function but that seems wrong. It will probably attach multiple event listeners to the same item. So, all items will have many event listeners attached to them but I am not sure.

What is the best way to attach event listeners to all current and future items in a project layer in Paper.js?

Link: http://paperjs.org/reference/item/#onmouseenter

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You just have to attack an event listener to the Tool.
The event argument that will be passed to the listener will then have an item property which is the event target item.
Here is a simple sketch demonstrating this.

tool.onMouseDown = (event) => console.log(event.item && event.item.name);

let id = 0;

drawRandomCircle();
setInterval(drawRandomCircle, 2000);

new PointText({
    content: 'Click on a circle to log its name',
    point: view.center + [0, -80],
    justification: 'center'
});

function drawRandomCircle() {
    new Path.Circle({
        center: Point.random() * view.size,
        radius: 50,
        fillColor: Color.random(),
        name: `item ${++id}`
    });
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda