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:
- use
svg
renderer - whenever create shape have private property
_renderer
- you can access
elem
corresponding dom element - 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.