sensors-orientation
v1.2.0
Published
<a href="https://imgse.com/i/pPwj35V"><img src="https://s1.ax1x.com/2023/08/31/pPwj35V.png" alt="pPwj35V.png" border="0" /></a>
Downloads
2
Readme
sensors-orientation
A draggable DOM component that simulates Orientation, similar to the browser devtools, and matches the behavior of the browser devtools.
Usage
Demo
yarn
yarn demo
Install
yarn add sensors-orientation
Use in Vue
import { ref, onMounted } from 'vue'
import registerOrientation from 'sensors-orientation'
import 'sensors-orientation/dist/index.css'
// import type {OrientationView} from 'sensors-orientation'
const manager = ref(null)
function reset() {
manager.value.resetDeviceOrientation();
}
// 生命周期钩子
onMounted(() => {
manager.value = registerOrientation(document.querySelector('.orientation'));
manager.value.onChangeDeviceOrientation(args => {
console.error('onChangeDeviceOrientation', args);
})
})
API
registerOrientation
register orientation, use it first.
params
- dom:
HTMLElement
return
Return a manager
of type OrientationView
manager.resetDeviceOrientation
reset the orientation data to [0, 90, 0]
manager.onChangeDeviceOrientation
listens the orientation data changes and triggers a callback
params
- callback:
ChangedFCType
manager.setDeviceOrientation
set device orientation, like user input.
params
- orientation:
OrientationType
Type
OrientationType
OrientationView