New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

motion-sensitive

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

motion-sensitive

Lorem ipsum sit amet

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

motion-sensitive

CircleCI Status Codecov npm npm npm semantic-release

The plugin MotionSensitive create an instance which allows to follow the movements of an element and to deduce a possible direction.

Install

npm i motion-sensitive
or
yarn add motion-sensitive

Importing

import MotionSensitive from "motion-sensitive";

Quick start

usage motion-sensitive plugin

const motion = MotionSensitive();
const btn = document.querySelector("#btn1");

const { x, y, width, height } = btn.getBoundingClientRect();
const point1 = { x, y: y + height };
const point2 = { x: x + width, y: y };

document.body.addEventListener("mousemove", (e) => {
    const mouseX = e.pageX - document.body.offsetLeft;
    const mouseY = e.pageY - document.body.offsetTop;
    motion.trackPoint({
        x: mouseX,
        y: mouseY
    });
});

function spy() {
    if (motion.isLookedIn(point1, point2)) {
        btn.classList.add("wakeup");
    } else {
        btn.classList.remove("wakeup");
    }
    requestAnimationFrame(spy);
}

spy();

click to see DEMO

Methods

MotionSensitive({gap, sensibility})

argumenttypedefaultDescription
gatNumber5angle gap between target and current direction
sensibilityNumber1average of the n last direction
const motion = MotionSensitive({
    gap: 10,
    sesibility: 10
});

.isLookedAt(obj)

argumenttypeDescription
objObjecttarget coordinates {x,y}
returnDescription
booleantrue when the tracked positions indicate that they are going towards the target else false
motion.isLookedAt({ x: 1, y: 2 }); // true or false

.isLookedIn(obj1, obj2)

argumenttypeDescription
obj1Objecttarget coordinates {x,y}
obj2Objecttarget coordinates {x,y}
returnDescription
booleantrue when the tracked positions indicate that they are going towards between this targets else false
motion.isLookedIn({ x: 1, y: 2 }, { x: 1, y: 1 }); // true or false

FAQs

Package last updated on 29 Jun 2020

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