-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-xy.mustache
35 lines (30 loc) · 992 Bytes
/
node-xy.mustache
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
33
34
35
<link href="{{componentAssets}}/node.css" rel="stylesheet" type="text/css">
<div class="intro">
<p>This example shows how to position an element based on the document XY coordinate system.</p>
<p>Click anywhere on the gray box below and the little orange box will move to the click position.</p>
</div>
<div class="example">
{{>node-xy-source}}
</div>
<h2>Setting up the HTML</h2>
<p>First we need some HTML to work with.</p>
```
<div id="demo-stage">
<span id="demo"></span>
</div>
```
<h2>Getting the Dimensions</h2>
<p>In this example, we will listen for clicks on the document and update the position of our demo node to match the click position.</p>
```
var onClick = function(e) {
Y.one('#demo').setXY([e.pageX, e.pageY]);
};
```
<p>The last step is to assign the click handler to the <code>document</code> to capture all <code>click</code> events.</p>
```
Y.one('#demo-stage').on('click', onClick);
```
<h2>Complete Example Source</h2>
```
{{>node-xy-source}}
```