0.0.11 • Published 2 years ago

@imnull/movable v0.0.11

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Movable

通过 mousedown mousemove mouseup 事件,封装用户操作,快速创建拖移效果的基础模块。

useMovable

import { useEffect, useState } from 'react'
import { useMovable } from '@imnull/movable'

export default () => {
    const [target, setTarget] = useState<HTMLElement | null>(null)
    const [pos, setPos] = useState({ x: 0, y: 0 })

    useEffect(() => {
        if (target) {
            const m = useMovable({
                update: setPos,
            })
            m.init(target)
            return () => {
                m.dispose()
            }
        }
    }, [target])

    return <>
        <h1>Playgound</h1>
        <div className='block' ref={setTarget} style={{ transform: `translateX(${pos.x}px) translateY(${pos.y}px)` }}>block</div>
    </>
}
0.0.10

2 years ago

0.0.11

2 years ago

0.0.9

2 years ago

0.0.6

2 years ago