Atropos Documentation
repository·master·Indexed 25 days ago
https://github.com/nolimits4web/atroposA lightweight, open-source JavaScript library for creating touch-friendly 3D parallax hover effects. Atropos supports vanilla JS, React, and Web Components, providing a configurable system to apply rotation, scaling, and depth offsets to elements via the AtroposOptions API and data attributes.
What's inside Atropos
- Atropos is a lightweight, free, and open-source JavaScript library designed to create 3D parallax hover effects. It is optimized for touch interactions and is available in three formats: vanilla JavaScript, React, and as a Web Component.
Build Atropos for Development
masterTo build a development version of Atropos, first install all dependencies from the repository root, then run the development build command. The output will be available in the
build/folder.$ npm install $ npm run build:devBuild Atropos for Production
masterTo generate the production-ready version of Atropos, run the production build command. The resulting stable JS and CSS files will be located in the
package/folder. Do not use files from thebuild/folder for production environments.$ npm run build:prodRun Atropos Demos
masterDemos for the different versions of Atropos are located in the
./playgroundfolder. You can run them using the following commands:- Core (HTML/JS):
npm run core - React:
npm run react
- Core (HTML/JS):
Access Atropos documentation and website
masterFor detailed implementation guides, API references, and examples, visit the official Atropos resources:
- Website: https://atroposjs.com/
- Documentation: https://atroposjs.com/docs
Apply parallax offsets to child elements
masterYou can create depth within an Atropos container by applying offsets to child elements using
data-*attributes. Atropos will automatically calculate their movement based on the parent's rotation.Supported Attributes:
data-atropos-offset: A number representing the percentage offset. A value of10means the child moves 10% of the rotation intensity.data-atropos-opacity: A semicolon-separated list of two numbers (e.g.,0;1) representing the minimum and maximum opacity during rotation.
Example HTML Structure:
<div class="atropos-container"> <div class="atropos-rotate"> <div class="atropos-scale"> <div class="atropos-inner"> <!-- This child will move with a 20% offset --> <div data-atropos-offset="20">Child Content</div> <!-- This child will fade from 0 to 1 opacity --> <div data-atropos-opacity="0;1">Fading Child</div> </div> </div> </div> </div>Atropos configuration options
masterThe
paramsobject passed to theAtroposconstructor accepts the following configuration keys:Key Type Default Description alwaysActiveboolean falseIf true, the effect is always applied without needing pointer interaction.activeOffsetnumber 50The Z-axis offset applied to the scale element when active. shadowOffsetnumber 50The Z-axis offset for the shadow element. shadowScalenumber 1The scale applied to the shadow element. durationnumber 300Transition duration in milliseconds. rotateboolean trueWhether to enable rotation. rotateTouchboolean trueWhether to enable rotation on touch devices. Can be 'scroll-y'or'scroll-x'to handle scrolling conflicts.rotateXMaxnumber 15Maximum rotation angle on the X axis. rotateYMaxnumber 15Maximum rotation angle on the Y axis. rotateXInvertboolean falseIf true, inverts the X rotation direction.rotateYInvertboolean falseIf true, inverts the Y rotation direction.stretchXnumber 0Percentage of X-axis stretching based on rotation. stretchYnumber 0Percentage of Y-axis stretching based on rotation. stretchZnumber 0Z-axis stretching based on rotation. commonOriginboolean trueIf true, uses a common transform origin for rotation.shadowboolean trueWhether to enable the shadow effect. highlightboolean trueWhether to enable the highlight effect. onEnterfunction nullCallback triggered when the element is activated. onLeavefunction nullCallback triggered when the element is deactivated. onRotatefunction nullCallback triggered on every rotation update. Receives (rotateX, rotateY).Configure Atropos with AtroposOptions
masterWhen initializing Atropos, you can pass an
AtroposOptionsobject to customize the behavior of the effect.Key configuration properties include:
el: The targetHTMLElementorCSSSelectorto apply the effect to.eventsEl: TheHTMLElementorCSSSelectorthat triggers the effect (e.g., a container for mouse/touch events).alwaysActive: Iftrue, the effect is always active.activeOffset: Offset for the active state.shadowOffset,shadowScale: Controls for the shadow effect.duration: Animation duration.rotate,rotateTouch: Enables rotation on mouse or touch.rotateTouchcan be set to'scroll-x'or'scroll-y'.rotateXMax,rotateYMax: Maximum rotation angles.rotateXInvert,rotateYInvert: Whether to invert the rotation direction.stretchX,stretchY,stretchZ: Controls for the stretching effect.commonOrigin: Whether to use a common origin for the effect.shadow: Enables/disables the shadow effect.highlight: Enables/disables the highlight effect.onEnter: Callback function triggered when the element becomes active.onLeave: Callback function triggered when the element becomes inactive.onRotate: Callback function triggered during rotation, receivingxandycoordinates:(x: number, y: number) => void.
Use the Atropos constructor
masterTo create an Atropos effect, call theAtroposfunction with anAtroposOptionsobject. This returns anAtroposInstancewhich allows you to interact with or destroy the effect.Manage AtroposInstance lifecycle
masterThe
AtroposInstanceobject returned by the constructor provides access to the current state of the effect and a method to clean it up.Properties:
el: TheHTMLElementbeing controlled.isActive: Boolean indicating if the effect is currently active.destroyed: Boolean indicating if the instance has been destroyed.params: The originalAtroposOptionsused for initialization.
Methods:
destroy(): Removes the effect and cleans up event listeners.
Listen to Atropos Web Component events
masterThe
<atropos-component>element dispatches several custom events that you can listen to for interaction tracking:enter: Dispatched when the user enters the element.leave: Dispatched when the user leaves the element.rotate: Dispatched during rotation. The rotation data is available in theevent.detailproperty.
Initialize Atropos for 3D parallax effects
masterTo create a 3D parallax effect, instantiate the
Atroposconstructor by passing an object containing the target element and configuration parameters. The constructor returns an object that allows you to manuallydestroythe instance.Parameters:
el: The target DOM element (or a CSS selector string) to apply the effect to.eventsEl: (Optional) The element that listens for pointer events. Defaults toelif not provided.isComponent: (Optional) Boolean. Iftrue,childrenRootElis set to the host of the parent node (useful for Web Components).params: Configuration object (see Atropos configuration options).