Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Here is how to listen for mouse/touch events on the empty areas of the stage.</strong></p> <p>To listen for mouse/touch events on the stage (any non-object area), you need to add a new layer containing a rectangle that fills the stage. Then you can handle mouse/touch events on the empty stage areas: eventLayer.on(“dblclick”,function(e) {//do doubleclick stuff}</p> <p>That layer code looks like this:</p> <pre><code> // Create a layer that will listen for mouse/touch events var eventLayer = new Kinetic.Layer(); eventLayer.add(new Kinetic.Rect({ x:0, y:0, width:400, height:300 })); stage.add(eventLayer); // TEST--listen for "dblclick" eventLayer.on('dblclick', function(evt) { alert("2click"); }); </code></pre> <p>Here is the full code and a Fiddle: <a href="http://jsfiddle.net/m1erickson/gNMRq/" rel="nofollow">http://jsfiddle.net/m1erickson/gNMRq/</a></p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; body { margin: 0px; padding: 0px; } &lt;/style&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://www.html5canvastutorials.com/libraries/kinetic-v4.3.2-beta.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt;&lt;/div&gt; &lt;script&gt; var stage = new Kinetic.Stage({ container: 'container', width: 400, height: 300 }); var layer = new Kinetic.Layer(); var rectX = stage.getWidth() / 2 - 50; var rectY = stage.getHeight() / 2 - 25; var box = new Kinetic.Rect({ x: rectX, y: rectY, width: 100, height: 50, fill: '#00D2FF', stroke: 'black', strokeWidth: 4, draggable: true }); // add cursor styling box.on('mouseover', function() { document.body.style.cursor = 'pointer'; }); box.on('mouseout', function() { document.body.style.cursor = 'default'; }); // Create a layer that will listen for mouse/touch events var eventLayer = new Kinetic.Layer(); eventLayer.add(new Kinetic.Rect({ x:0, y:0, width:400, height:300 })); stage.add(eventLayer); // TEST--listen for "dblclick" eventLayer.on('dblclick', function(evt) { alert("2click"); }); layer.add(box); stage.add(layer); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload