Socket
Socket
Sign inDemoInstall

@hscmap/inertial-mouse

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hscmap/inertial-mouse

Inertial Mouse for TypeScript * Wraps native MouseEvent and emit pseudo mousemove events with inertial smooth motion. * [Working Demo](https://michitaro.github.io/inertial-mouse)


Version published
Weekly downloads
16
increased by433.33%
Maintainers
1
Weekly downloads
 
Created
Source

Inertial Mouse

Inertial Mouse for TypeScript

  • Wraps native MouseEvent and emit pseudo mousemove events with inertial smooth motion.
  • Working Demo

Install

npm instasll --save @hscmap/inertial-mouse

Example (source code of the working demo)

import { InertialMouse, Coord } from "@hscmap/inertial-mouse"


window.addEventListener('load', e => {
    const sandbox = document.querySelector('.sandbox') as HTMLElement
    const cursor = document.querySelector('.cursor') as HTMLElement
    const dxText = document.querySelector('[name="dx"]') as HTMLInputElement
    const dyText = document.querySelector('[name="dy"]') as HTMLInputElement

    function setCursorPosition(r: Coord) {
        cursor.style.left = `${r.x}px`
        cursor.style.top = `${r.y}px`
    }

    const im = new InertialMouse(sandbox, {
        down: (e) => {
            setCursorPosition(e.r)
            cursor.classList.add('pressed')
        },
        up: () => {
            cursor.classList.remove('pressed')
        },
        move: (e) => {
            setCursorPosition(e.r)
            dxText.value = `${e.d.x}`
            dyText.value = `${e.d.y}`
        },
        movestart: () => cursor.classList.add('moving'),
        moveend: () => cursor.classList.remove('moving'),
    })

    document.addEventListener('change', e => {
        const target = e.target as HTMLInputElement
        if (target.matches('[name="slick"]'))
            im.slick = target.checked
        if (target.matches('[name="friction"]'))
            im.friction = Number(target.value)
        if (target.matches('[name="k"]'))
            im.k = Number(target.value)
    })
})


document.addEventListener('selectstart', e => e.preventDefault()) // disable selection

FAQs

Package last updated on 26 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc