Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stagas/relative-mouse

Get mouse position relative to a DOM element.
https://github.com/stagas/relative-mouse

dom element mouse relative

Last synced: 14 days ago
JSON representation

Get mouse position relative to a DOM element.

Awesome Lists containing this project

README

        


relative-mouse

Get mouse position relative to a DOM element.



npm i relative-mouse

pnpm add relative-mouse

yarn add relative-mouse

## API

# getRelativeMouse(el, { x, y }) src/index.ts#L6

getRelativeMouse(el, { x, y })  =>

    {

    # x


      number

    # y

      number

    }
# getRelativeMouseFromEvent(el, event) src/index.ts#L3

    # el


      HTMLElement

    # event

      MouseEvent | PointerEvent


    getRelativeMouseFromEvent(el, event)  =>


      {

      # x


        number

      # y

        number

      }

## Credits

- [get-element-offset](https://npmjs.org/package/get-element-offset) by [stagas](https://github.com/stagas) – Get accurate DOM element offset.

## Contributing

[Fork](https://github.com/stagas/relative-mouse/fork) or [edit](https://github.dev/stagas/relative-mouse) and submit a PR.

All contributions are welcome!

## License

MIT © 2022 [stagas](https://github.com/stagas)