Reputation: 235
I want to fire an event when an image is clicked on but only once, IE disable the functionality after the first click. I tried..
var img = new Kinetic.Image({
x: position[rand][0],
y: position[rand][1],
image: imageObj,
width: 106,
height: 118
});
img.on('mousedown', function(e) {
do stuff
e.stopPropagation();
}
and
img.on('mousedown', function() {
do stuff
return false;
}
any ideas?
Upvotes: 1
Views: 2859
Reputation: 47257
img.addEventListener("mousedown", function() {
// Do something
}, {once : true});
// You might also consider adding "capture : true" to replace stopPropogation
Upvotes: 1
Reputation: 123739
Use one
instead of on
to register the event just once.
img.one('mousedown', function(e) {
do stuff
e.stopPropagation();
}
You can also use off
to turn off the event inside the on
handler.
img.on('mousedown', function(e) {
$(this).off('mousedown'); //turn off the handler
do stuff
}
Upvotes: 2