### Install simpleParallax.js via npm or yarn Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Use npm or yarn to add the simpleParallax.js library to your project dependencies. ```sh #npm npm install simple-parallax-js #yarn yarn add simple-parallax-js ``` -------------------------------- ### Initialize simpleParallax in React Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Wrap your image component with the SimpleParallax component to apply the effect. No additional setup is required. ```javascript import SimpleParallax from "simple-parallax-js"; const Component = () => ( {"image"} ) ``` -------------------------------- ### React Props: Diagonal Movement Example Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Implement diagonal parallax movement by setting the 'orientation' prop to a combination of directions like 'down right'. The 'overflow' prop can be set to true to allow the image to bleed outside its container. ```tsx import React from "react"; import SimpleParallax from "simple-parallax-js"; // Diagonal movement example const DiagonalParallax = () => ( Wide landscape ); ``` -------------------------------- ### Import simpleParallax.js in React or Vanilla JS Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Import the library into your project. Use the default import for React and the '/vanilla' path for vanilla JavaScript. ```javascript //React version import SimpleParallax from 'simple-parallax-js'; //Vanilla Version import SimpleParallax from "simple-parallax-js/vanilla"; ``` -------------------------------- ### Vanilla JS Orientation Reference Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Demonstrates all eight orientation strings and their axis behavior for parallax effects. Each orientation is applied to a corresponding image. ```javascript import SimpleParallax from "simple-parallax-js/vanilla"; const demos = [ { orientation: "up", description: "Image moves up as you scroll down (default)" }, { orientation: "down", description: "Image moves down as you scroll down" }, { orientation: "left", description: "Horizontal: image moves left" }, { orientation: "right", description: "Horizontal: image moves right" }, { orientation: "up left", description: "Diagonal: up + left" }, { orientation: "up right", description: "Diagonal: up + right" }, { orientation: "down left", description: "Diagonal: down + left" }, { orientation: "down right", description: "Diagonal: down + right" }, ]; // Apply each orientation to a corresponding image demos.forEach(({ orientation }, index) => { const img = document.querySelectorAll("img.demo")[index]; new SimpleParallax(img, { orientation, scale: 1.4 }); }); ``` -------------------------------- ### Configuration Options Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md These are the configuration options that can be passed when initializing SimpleParallax.js to customize the parallax effect. ```APIDOC ## Configuration Options ### scale - **Type**: Number - **Description**: Controls the intensity of the parallax effect. Higher values result in a more pronounced effect but may diminish image quality. It's recommended to use a proportionally larger image to maintain quality when increasing scale. ### overflow - **Type**: Boolean - **Description**: Determines if the image should translate beyond its natural flow, potentially overlapping content. Defaults to `false` for layout consistency. ### delay - **Type**: Number - **Description**: Sets a delay in seconds for the image's translation after the user stops scrolling, creating a smoother effect. Be aware of potential issues on iOS devices. ### transition - **Type**: String - **Description**: Applies CSS transitions to the delay setting, such as `ease` or `ease-in-out`, for a more refined animation. ### maxTransition - **Type**: Number - **Description**: Defines the maximum extent of the parallax animation, typically a percentage of the user's viewport. Defaults to 100%. ### src - **Type**: String - **Description**: (Vanilla version only) Specifies the source URL or local path for the image. ### customContainer - **Type**: String or Node - **Description**: (Vanilla version only) Allows specifying a custom container for parallax calculations if the image is within a scrollable element other than the body. ### customWrapper - **Type**: String - **Description**: (Vanilla version only) Enables the use of a custom wrapper element, applying the `simpleParallax` class and `overflow: hidden` style. ``` -------------------------------- ### Methods Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Available methods for interacting with SimpleParallax.js instances. ```APIDOC ## Methods ### refresh - **Description**: Recalculates all image positions for the parallax effect. This method is automatically called on window resize by default. - **Usage**: ```javascript var images = document.querySelectorAll('img'); var instance = new SimpleParallax(images); instance.refresh(); ``` ### destroy - **Description**: Removes the parallax effect and cleans up associated event listeners and styles, effectively destroying the instance. - **Usage**: ```javascript var images = document.querySelectorAll('img'); var instance = new SimpleParallax(images); instance.destroy(); ``` ``` -------------------------------- ### Configure simpleParallax settings in Vanilla JS Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Initialize simpleParallax with an options object to customize parameters like delay, orientation, scale, overflow, customContainer, and customWrapper. ```javascript var images = document.querySelectorAll('.thumbnail'); new SimpleParallax(images, { delay: 0, orientation: 'down', scale: 1.3, overflow: true, customContainer: '.container', customWrapper: '.wrapper' }); ``` -------------------------------- ### SimpleParallax Component Usage Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Demonstrates basic and advanced usage of the SimpleParallax React component, including how to configure its properties for different parallax effects. ```APIDOC ## SimpleParallax Component ### Description The `SimpleParallax` React component wraps a single child image element and applies a scroll-driven parallax transform to it. It uses `IntersectionObserver` to track visibility and a passive scroll manager to fire `requestAnimationFrame` only while the element is on screen. The component clones its child to attach an internal `ref`, so no manual ref is needed. ### Basic Usage ```tsx import React from "react"; import SimpleParallax from "simple-parallax-js"; // Basic usage — image moves upward as the user scrolls down const BasicExample = () => ( Hero ); ``` ### Full Example with Props ```tsx import React from "react"; import SimpleParallax from "simple-parallax-js"; // All props explicitly set const FullExample = () => ( 1); higher = more pronounced effect delay={0.6} // seconds of CSS transition lag after scroll stops transition="ease-in-out" // CSS easing for the delay transition overflow={false} // false = clip overflow with hidden wrapper; true = allow bleed maxTransition={75} // cap parallax at 75% of the full animation range > Parallax photo ); ``` ### With Next.js Image Component ```tsx import Image from "next/image"; import SimpleParallax from "simple-parallax-js"; const NextExample = () => ( Banner ); ``` ### Diagonal Movement Example ```tsx import React from "react"; import SimpleParallax from "simple-parallax-js"; const DiagonalParallax = () => ( Wide landscape ); ``` ``` -------------------------------- ### Initialize simpleParallax on multiple images in Vanilla JS Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Select multiple image elements using querySelectorAll and pass the NodeList to SimpleParallax to apply the effect to all selected images. ```javascript const images = document.querySelectorAll('img'); new SimpleParallax(images); ``` -------------------------------- ### Initialize SimpleParallax with Elements and Options Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Instantiate SimpleParallax with a DOM element, NodeList, HTMLCollection, or CSS selector. The constructor returns immediately if browser APIs are unsupported or reduced motion is preferred. ```javascript import SimpleParallax from "simple-parallax-js/vanilla"; // Single element const hero = document.querySelector(".hero-image"); const heroParallax = new SimpleParallax(hero, { orientation: "up", scale: 1.3, }); // Multiple elements via NodeList const images = document.querySelectorAll("img.parallax"); const parallax = new SimpleParallax(images, { delay: 0.6, orientation: "down", scale: 1.4, overflow: false, transition: "cubic-bezier(0,0,0,1)", maxTransition: 80, // percentage (1–99) }); // Via CSS selector string const bySelector = new SimpleParallax(".thumbnail", { orientation: "left", scale: 1.2, }); // Video elements are also supported const video = document.querySelector("video"); const videoParallax = new SimpleParallax(video, { orientation: "up", scale: 1.3, }); ``` -------------------------------- ### Configure simpleParallax settings for Next.js Image component Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Use simpleParallax with the Next.js Image component by passing configuration options as props. Ensure to include width and height for the Image component. ```javascript import SimpleParallax from "simple-parallax-js"; import Image from "next/image"; const Component = () => ( {"image"} ) ``` -------------------------------- ### SimpleParallax Constructor Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Initialize SimpleParallax with a DOM element, NodeList, HTMLCollection, or CSS selector, and an optional options object. Instances share a single requestAnimationFrame loop. Initialization is skipped if browser support is lacking or reduced motion is preferred. ```APIDOC ## `new SimpleParallax(elements, options)` ### Description Initializes a new SimpleParallax instance. ### Parameters - **elements**: (DOM element, NodeList, HTMLCollection, string) - The element(s) to apply parallax effects to. - **options**: (object, optional) - Configuration options for the parallax effect. - **orientation**: (string, optional) - Direction of the parallax effect ('up', 'down', 'left', 'right'). - **scale**: (number, optional) - Scale factor for the parallax effect. - **delay**: (number, optional) - Delay for the parallax effect. - **overflow**: (boolean, optional) - Whether to apply overflow hidden. - **transition**: (string, optional) - CSS transition timing function. - **maxTransition**: (number, optional) - Maximum transition percentage (1-99). - **customContainer**: (DOM element or string, optional) - A specific ancestor element to use for scroll calculations. - **customWrapper**: (string, optional) - A CSS selector for an existing element to use as the overflow wrapper. ### Returns - (SimpleParallax instance) - The initialized parallax instance, or null if initialization failed. ``` -------------------------------- ### Initialize simpleParallax on video elements Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Apply parallax effects to video elements by selecting them using getElementsByTagName and passing the collection to the SimpleParallax constructor. ```html ``` ```javascript var video = document.getElementsByTagName('video'); new SimpleParallax(video); ``` -------------------------------- ### Initialize simpleParallax on a single image in Vanilla JS Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Select an image element by its class name and instantiate SimpleParallax with it. This applies the parallax effect to the selected image. ```html image ``` ```javascript const image = document.getElementsByClassName('thumbnail'); new SimpleParallax(image); ``` -------------------------------- ### Prefers Reduced Motion Support (Vanilla JS) Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Automatically detects OS-level reduced-motion preference. If enabled, parallax animations are skipped. No configuration is required. ```javascript import SimpleParallax from "simple-parallax-js/vanilla"; const instance = new SimpleParallax(document.querySelectorAll("img"), { scale: 1.3, }); // instance is silently inactive for reduced-motion users. ``` -------------------------------- ### instance.refresh() Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Recalculates all viewport positions and element offsets. This method should be called after dynamic content changes or programmatic scroll adjustments. ```APIDOC ## `instance.refresh()` ### Description Recalculates element positions and offsets. Call this after dynamic content changes or layout adjustments. ### Usage Call this method on an existing SimpleParallax instance to update its measurements. ``` -------------------------------- ### Initialize and Refresh SimpleParallax Instance Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Instantiate SimpleParallax on selected image elements and then call the refresh method to recalculate positions. The refresh method is automatically called on window resize. ```javascript var images = document.querySelectorAll('img'); var instance = new SimpleParallax(images); instance.refresh(); ``` -------------------------------- ### Configure simpleParallax settings in React Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Pass configuration options as props to the SimpleParallax component in React to customize the parallax effect. Options include delay, orientation, scale, overflow, and maxTransition. ```javascript import SimpleParallax from "simple-parallax-js"; const Component = () => ( {"image"} ) ``` -------------------------------- ### SimpleParallaxProps Interface Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Details the TypeScript interface for all configuration options available for the `` component. ```APIDOC ## React Props: `SimpleParallaxProps` ### Description The TypeScript interface for all `` configuration options. ### Props - **delay** (number) - Optional - Default: `0.4` (seconds) - **orientation** (Orientation) - Optional - Default: `"up"` - Possible values: `"up"`, `"right"`, `"down"`, `"left"`, `"up left"`, `"up right"`, `"down left"`, `"down right"` - **scale** (number) - Optional - Default: `1.4` - **overflow** (boolean) - Optional - Default: `false` - **transition** (string) - Optional - Default: `"cubic-bezier(0,0,0,1)"` - **maxTransition** (number | null) - Optional - Default: `null` (no cap) - **children** (React.ReactNode) - Required - The child element to apply parallax to. ``` -------------------------------- ### Prefers Reduced Motion Support (React) Source: https://context7.com/geosigno/simpleparallax.js/llms.txt The useReduceMotion hook provides automatic behavior for reduced motion. It clears transform/transition styles when reduced motion is detected. ```javascript import SimpleParallax from "simple-parallax-js"; const AccessibleHero = () => ( Hero {/* No parallax applied when prefers-reduced-motion: reduce */} ); ``` -------------------------------- ### Refresh Parallax Instance After Dynamic Content Changes Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Call `instance.refresh()` to recalculate viewport positions and element offsets. This is necessary after dynamic content changes like lazy-loaded images, DOM mutations, or CSS transitions that affect layout. ```javascript import SimpleParallax from "simple-parallax-js/vanilla"; const images = document.querySelectorAll("img.parallax"); const instance = new SimpleParallax(images, { scale: 1.3 }); // Automatically triggered on window resize (debounced 200ms). // Call manually after layout changes: window.addEventListener("load", () => { instance.refresh(); // re-measure after web fonts and lazy images settle }); // After an accordion or tab panel opens: document.querySelector(".accordion-toggle").addEventListener("click", () => { requestAnimationFrame(() => instance.refresh()); }); ``` -------------------------------- ### Use customWrapper Option to Reuse Existing Elements Source: https://context7.com/geosigno/simpleparallax.js/llms.txt The `customWrapper` option allows using an existing element as the overflow wrapper instead of injecting a new `
`. The specified selector must match an ancestor of the image, and the `.simpleParallax` class with `overflow: hidden` is automatically applied. ```javascript import SimpleParallax from "simple-parallax-js/vanilla"; // HTML:
const images = document.querySelectorAll(".card__img"); new SimpleParallax(images, { scale: 1.4, customWrapper: ".card", // reuses .card as the clipping wrapper }); // Result: .card gets class="simpleParallax card" style="overflow:hidden" ``` -------------------------------- ### React Usage with Next.js Image Component Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Integrate simpleParallax.js with the Next.js Image component for optimized image loading and parallax effects. Ensure the Image component is passed as a child to SimpleParallax. ```tsx import Image from "next/image"; import SimpleParallax from "simple-parallax-js"; const NextExample = () => ( Banner ); ``` -------------------------------- ### Basic React Usage: SimpleParallax Component Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Use the SimpleParallax component to wrap an image for basic upward parallax scrolling. No manual ref is needed as the component clones its child. ```tsx import React from "react"; import SimpleParallax from "simple-parallax-js"; // Basic usage — image moves upward as the user scrolls down const BasicExample = () => ( Hero ); ``` -------------------------------- ### Advanced React Usage: Full SimpleParallax Configuration Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Configure all available props for the SimpleParallax component to customize the parallax effect. This includes orientation, scale, delay, transition, and overflow behavior. ```tsx import React from "react"; import SimpleParallax from "simple-parallax-js"; // All props explicitly set const FullExample = () => ( 1); higher = more pronounced effect delay={0.6} // seconds of CSS transition lag after scroll stops transition="ease-in-out" // CSS easing for the delay transition overflow={false} // false = clip overflow with hidden wrapper; true = allow bleed maxTransition={75} // cap parallax at 75% of the full animation range > Parallax photo ); ``` -------------------------------- ### Use customContainer Option for Scrollable Ancestors Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Redirect scroll calculations to a specific scrollable ancestor using the `customContainer` option. This is useful when parallax images are within an overflow-scrolling container, not the main page body. ```javascript import SimpleParallax from "simple-parallax-js/vanilla"; // Images inside a scrollable modal/sidebar const container = document.querySelector(".scrollable-panel"); const images = container.querySelectorAll("img"); const parallax = new SimpleParallax(images, { orientation: "up", scale: 1.3, customContainer: container, // pass the Node directly, or a CSS selector string }); ``` -------------------------------- ### customWrapper Option Source: https://context7.com/geosigno/simpleparallax.js/llms.txt The `customWrapper` option allows you to use an existing element as the overflow wrapper, preventing the library from injecting a new `div`. The specified selector must match an ancestor of the image. ```APIDOC ## `customWrapper` Option ### Description Uses an existing element as the overflow wrapper instead of injecting a new `
`. ### Parameters - **customWrapper**: (string) - A CSS selector for the existing element to use as the overflow wrapper. The `.simpleParallax` class and `overflow: hidden` will be added to this element. ``` -------------------------------- ### Destroy Parallax Instance to Clean Up Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Use `instance.destroy()` to completely remove the parallax effect. This removes inline styles, unwraps injected wrapper elements, disconnects observers, and cancels the animation loop if no instances remain. ```javascript import SimpleParallax from "simple-parallax-js/vanilla"; const images = document.querySelectorAll("img.parallax"); const instance = new SimpleParallax(images, { scale: 1.4, delay: 0.3 }); // Destroy when navigating away (e.g., SPA route change) function cleanup() { instance.destroy(); // All inline styles removed, wrapper divs unwrapped, // rAF loop cancelled if this was the last instance. } document.querySelector("#nav-link").addEventListener("click", cleanup); ``` -------------------------------- ### TypeScript Interface for SimpleParallax Props Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Defines the TypeScript types for all configuration options available for the SimpleParallax React component. This includes defaults for delay, orientation, scale, overflow, transition, and maxTransition. ```ts import { SimpleParallaxProps, Orientation } from "simple-parallax-js"; // Full type definition (from src/react/types/index.ts): // type Orientation = // | "up" | "right" | "down" | "left" // | "up left" | "up right" | "down left" | "down right"; // interface SimpleParallaxProps { // delay?: number; // default: 0.4 (seconds) // orientation?: Orientation; // default: "up" // scale?: number; // default: 1.4 // overflow?: boolean; // default: false // transition?: string; // default: "cubic-bezier(0,0,0,1)" // maxTransition?: number | null; // default: null (no cap) // children?: React.ReactNode; // } ``` -------------------------------- ### instance.destroy() Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Completely removes the parallax instance, including inline styles, unwrapping elements, and disconnecting observers. The shared requestAnimationFrame loop is cancelled if no instances remain. ```APIDOC ## `instance.destroy()` ### Description Tears down the parallax instance, removing styles, unwrapping elements, and cancelling associated listeners and loops. ### Usage Call this method on an existing SimpleParallax instance to completely remove its effects and cleanup resources. ``` -------------------------------- ### customContainer Option Source: https://context7.com/geosigno/simpleparallax.js/llms.txt Use the `customContainer` option to specify a different scrollable ancestor for parallax calculations, useful for elements within modals or sidebars. ```APIDOC ## `customContainer` Option ### Description Redirects scroll calculations to a specific scrollable ancestor instead of the `window`. ### Parameters - **customContainer**: (DOM element or string) - The ancestor element to use for scroll calculations. ``` -------------------------------- ### Destroy SimpleParallax Instance Source: https://github.com/geosigno/simpleparallax.js/blob/master/README.md Remove the parallax effect and clean up any added classes or styles by destroying the SimpleParallax instance. This is useful when you no longer need the parallax effect on the images. ```javascript var images = document.querySelectorAll('img'); var instance = new SimpleParallax(images); instance.destroy(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.