-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcontrollers.js
More file actions
48 lines (35 loc) · 943 Bytes
/
controllers.js
File metadata and controls
48 lines (35 loc) · 943 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
import { LitElement } from "lit";
export class MouseController {
constructor(host) {
this.host = host;
host.addController(this);
this.x = 0;
this.y = 0;
}
_updatePosition =
/**
*
* @param {MouseEvent} event
*/
(event) => {
this.x = event.x;
this.y = event.y;
this.host.requestUpdate();
};
hostConnected() {
window.addEventListener('mousemove', this._updatePosition);
}
hostDisconnected() {
window.removeEventListener('mousemove', this._updatePosition);
}
}
class MyControlledElement extends LitElement {
constructor() {
super();
this.mouseCtrl = new MouseController(this);
}
render() {
return `Cursor position: ${this.mouseCtrl.x} - ${this.mouseCtrl.y}`;
}
}
customElements.define("my-controlled-element", MyControlledElement);