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

92
Views
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 answers
Answer question

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 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!