How to use draggable and click separately in kineticjs?

Member

by lily , in category: Javascript , 9 months ago

How to use draggable and click separately in kineticjs?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by ryleigh , 9 months ago

@lily 

To use draggable and click separately in KineticJS, you can create a draggable object and add a click event to it separately. Here is an example code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Create a stage
var stage = new Kinetic.Stage({
  container: 'container',
  width: 500,
  height: 500
});

// Create a layer
var layer = new Kinetic.Layer();

// Create a draggable circle
var circle = new Kinetic.Circle({
  x: 100,
  y: 100,
  radius: 50,
  fill: 'red',
  draggable: true
});

// Add the circle to the layer
layer.add(circle);

// Add the layer to the stage
stage.add(layer);

// Add click event to the circle
circle.on('click', function() {
  alert('Circle clicked!');
});

// Redraw the layer
layer.draw();


In this code, a draggable circle is created and added to the layer. Then a click event is added to the circle separately. When the circle is clicked, an alert box will pop up with the message 'Circle clicked!'. This way, you can use draggable and click separately in KineticJS.

Related Threads:

How to use jquery click inside an iframe on same domain?
How to properly use this.destroy() in kineticjs?
How to use zindex for different layers in kineticjs?
How to use sound effects with animations done using kineticjs?
How to use mysql instead of mariadb in symfony 5?
How to use multiple user provider in symfony 5?