Interact is essentially a wrapper on top of touch and mouse events. It exists to make the process of writing apps / demos that handle touch events both simpler to write and also allow them to support mouse events easily.
Events are distributed using eve.
Interact is distributed under an MIT License
For the purposes of more terse event names, the following events have been renamed:
- interact.pointer.down => interact.down
- interact.pointer.move => interact.move
- interact.pointer.up => interact.up
Handling simple down, move, and up events is easy:
eve.on('interact.down', function(evt, absXY, relXY) {
console.log('pointer down @ ', absXY);
});
// handle pointer move events
eve.on('interact.move', function(evt, absXY, relXY) {
console.log('pointer move @ ', absXY);
});
// handle pointer up events
eve.on('interact.up', function(evt, absXY, relXY) {
console.log('pointer up @ ', absXY);
});
// watch the specified target
interact.watch('targetElementId');
Through the way eve behaves, the above event handlers would relay events captured for any watched elemnet. If you want to limit the event capture to a specific event then use the following syntax:
eve.on('interact.pointer.down.targetElementId', function(evt, absXY, relXY) {
console.log('pointer down @ ', absXY);
});
The original DOM event that was captured is available in the first argument of all interact fired events. In the case of derived events such as interact.tap
, interact.pan
and interact.zoom
the DOM event maps back to the last event that was captured that triggered the condition. For instance, in the case of a tap, the last event that would be processed would be an *up event so that is what is communicated back.
To be completed
To be completed.