Skip to content

A plugin for Keyframes that plays animations based on mouse distance from an element.

License

Notifications You must be signed in to change notification settings

Keyframes/Keyframes.Proximity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keyframes.Proximity

A plugin for Keyframes that plays animations based on mouse distance from an element.

Installation

import Proximity from '@keyframes/proximity';
Keyframes.plugin(Proximity);

Usage

const blockElem = document.getElementById('block');
const block = new Keyframes(blockElem);
block.proximity((obj) => {
  blockElem.style.boxShadow = `red 0 0 ${0.5 * obj.distancePercentage}px`;
});
{
  mouse, // Current mouse x and y.
  mouseDistance, // Distance from the element in pixels.
  viewPortDistance, // Distance from the edge of the viewport in pixels.
  distancePercentage, // Distance of the mouse from the target element as a percentage where zero is the viewport edge.
  targetEdge, // Closest point on the edge of the target object to the mouse.
  viewPortEdge, // Closest point on the edge of the viewport to the target edge.
  collision: !mouseDistance, // Boolean if the mouse is over the top of the element.
}

About

A plugin for Keyframes that plays animations based on mouse distance from an element.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published