panGesture
panGesture là một hàm giúp bạn có thể di chuyển một phần tử trên màn hình bằng cách kéo thả.
Ví dụ
import { panGesture } from '@xobuilder/utils';
const pan = panGesture({
element: document.querySelector('.box'),
onStart: () => {
// do something
},
onMove: (gestureState, event) => {
// gestureState là 1 đối tượng có 4 thuộc tính dx, dy, vx, vy
// dx, dy là khoảng cách di chuyển theo trục x, y
// vx, vy là vận tốc di chuyển theo trục x, y
},
onEnd: (gestureState, event) => {
// do something
},
});
// Các method
// Set lại dx dy
pan.setValue({ dx: 0, dy: 0 });
// Destroy huỷ bỏ các listener
pan.destroy();