javascript - How to capture a click event on a shape or group in two.js? -


i have drawn shape using two.js , want write code handle click events on shape. not canvas, on shape itself.

front_left.domelement = $('#two-' + front_left.id)     .css('cursor', 'pointer')     .click(function(e){         alert("hello world!");     }); 

this code taken answer seems should work:

circle.domelement = $('#two-' + circle.id)   .css('cursor', 'pointer')   .click(function(e) {     circle.fill = getnonmainrandomcolor(getrandomcolor());   }); 

but doesn't work me using latest jquery , latest two.js, , doesn't seem work in the example, since code reads if clicking on circles supposed make colour changes nothing happens on browser or computer i've tried.

so, how can capture , respond click events of shapes/groups drawn two.js?

thanks message. reason answer doesn't work anymore because two.js has changed since then. i've added example here. gist of that:

  1. use svg renderer
  2. whenever create shape have private property _renderer
  3. you can access elem corresponding dom element
  4. but! make sure renderer has updated before access it

e.g:

var shape = two.makecircle(two.width / 2, two.height / 2, 50); two.update(); shape._renderer.elem.addeventlistener('click', handler, false); 

and, if you're feeling adventurous can mix renderers in this example.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -