export function useDrag() {
    const scroll = {
        x: 0,
        y: 0
    }

    // 开始拖动
    const dragStart = (e: DragEvent) => {
        scroll.x = e.clientX;
        scroll.y = e.clientY;
    }

    // 正在拖动
    const drag = (e: DragEvent) => {
        const { style } = e.target as HTMLDivElement;
        const x = e.clientX - scroll.x; // 计算偏移量

        style.setProperty('transform', 'translateX(' + x + 'px)');
    }

    const dragEnd = (e: DragEvent) => {
        const { style } = e.target as HTMLDivElement;
        const x = e.clientX - scroll.x; // 计算偏移量

        style.setProperty('transform', 'translateX(' + x + 'px)');
    }

    return {
        dragStart,
        drag,
        dragEnd,
    }
}