npm install pointer-point@1.1.0
<!DOCTYPE html>
<html>
<head>
<title>Dom list test</title>
<style type="text/css">
div{
background-color: #968096;
}
</style>
</head>
<body>
<div>
Some text
</div>
<script>
var pointer = require('../index');
var point = pointer(document.querySelector('div'));
point.on('move', function(e){
//Every movement is tracked.
console.log('point.x '+point.x);
console.log('point.y '+point.y);
console.log('point.down '+point.down);
});
point.on('down', function(e){
//Do something when the pointer is down.
});
point.on('up', function(e){
//Do something when the pointer is up.
});
</script>
</body>
</html>
Pass an element, or selector for an element, and get a point in return.
Use destroy to remove all tracking of the pointer. Useful if you don't need the reference to the element, or it's pointer anymore.
point.destroy();
point = null;
//Garbage collection is coming up.
Add events.
Remove events.
- move
- down
- up
- stroke
The move
event is used for the whole viewport. Not just the element you choose. This is useful for when you still need to track events when the pointer leaves the element.
The stroke
event is fired only when the mouse is down. On a touch interface move
, and stroke
are pretty much the same. stroke
is also emitted for the whole viewport.
Is the pointer down?
Is the pointer up?
The element passed to the factory constructor.
Read only x coordinate of the pointer.
Read only y coordinate of the pointer.
An internal reference to the point position.
Internally pointer-point uses events to track pointer position so until the cursor is moved, or there is a touch there will be no x/y positions. This shouldn't be a problem in most situations.