@okiba/pointer
v1.0.7
Published
Handles pointer movements and interceptions
Downloads
7
Readme
Okiba / Pointer
A wrapper class that collects normalized (both mouse and touch) pointer information
import Pointer from '@okiba/pointer'
import { MyCanvasApp } from '../path/to/my/components'
window.requestAnimationFrame(() => {
MyCanvasApp.update(Pointer.coords, Pointer.target)
})
Installation
npm i --save @okiba/pointer
Or import it directly in the browser
<script type="module" src="https://unpkg.com/@okiba/pointer/index.js"></script>
Usage
import Pointer from '@okiba/pointer'
Untranspiled code 🛑
Okiba UI packages are not transpiled, so don't forget to transpile them with your favourite bundler. For example, using Babel with Webpack, you should prevent imports from okiba to be excluded from transpilation, like follows:
{
test: /\.js$/,
exclude: /node_modules\/(?!(@okiba)\/).*/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
coords()
Coords getter
Returns
Object
{x, y}
target()
Last event target getter
Returns
Event
inview()
Returns pointer inview status
Returns
Boolean
lastEvent()
Last event getter
Returns
Event
matches(selectors, testAncestors)
Checks if last event target matches with given selectors
Arguments
+ selectors
: Array.<String>
The selectors list
+ testAncestors
: Boolean
If true, extends match test upward in the ancestors
Returns
String