### Installation
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Instructions on how to install Ukiyo.js using npm, yarn, or pnpm, and how to import it.
```APIDOC
## Installation
Install `ukiyojs` using your package manager of choice.
```sh
# npm
npm install ukiyojs
# yarn
yarn add ukiyojs
# pnpm
pnpm add ukiyojs
```
Import Ukiyo:
```javascript
import Ukiyo from "ukiyojs";
```
or import via CDN:
```html
```
```
--------------------------------
### Install Ukiyo.js
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Install the package using npm, yarn, or pnpm.
```shell
# npm
npm install ukiyojs
# yarn
yarn add ukiyojs
# pnpm
pnpm add ukiyojs
```
--------------------------------
### Full Page Parallax Example
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
A comprehensive example demonstrating multiple parallax sections with different configurations and smooth scroll integration, including image and CSS background parallax.
```html
Ukiyo.js Full Page Parallax
Welcome
```
--------------------------------
### Usage - HTML Structure
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Examples of how to structure your HTML for Ukiyo.js parallax effects with different element types.
```APIDOC
## Usage - HTML
Give the elements cool names like *ukiyo* to call them in scripts for parallax effects.
- #### 🏞 ` `
```html
```
- 🌅 __``__
```html
```
- 🎬 __``__
```html
```
- 🖼️ CSS `background-image`
```html
```
```
--------------------------------
### Using External requestAnimationFrame
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Guide on how to use an external requestAnimationFrame for Ukiyo.js animations.
```APIDOC
## Using external requestAnimationFrame
By default, parallax animation is automatically rendered using the library's `requestAnimationFrame`, but you can use an external `requestAnimationFrame` to run the animation.
```javascript
const parallax = new Ukiyo(".ukiyo", {
externalRAF: true
})
function raf(time) {
// animate parallax
parallax.animate()
requestAnimationFrame(raf)
}
requestAnimationFrame(raf)
```
Enable the `externalRAF` option, and then call the `animate()` method within your custom `requestAnimationFrame` to trigger the parallax animation.
```
--------------------------------
### HTML Element Setup
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Add the 'ukiyo' class to your HTML elements. Ukiyo.js supports images, picture elements, videos, and elements with CSS background-image.
```APIDOC
## HTML Element Setup
### Description
Add the parallax class to your HTML elements. Ukiyo.js supports images, picture elements, videos, and elements with CSS background-image.
### Method
None
### Endpoint
None
### Parameters
None
### Request Example
```html
```
### Response
None
```
--------------------------------
### Initialize Ukiyo.js Parallax
Source: https://github.com/yitengjun/ukiyo-js/blob/main/tests/demo/index.html
Initializes Ukiyo.js parallax on elements with the class 'ukiyo'. This is the basic setup for enabling parallax effects.
```javascript
const parallax = new Ukiyo('.ukiyo');
```
--------------------------------
### Setup HTML Elements for Parallax
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Apply the parallax effect to images, picture elements, videos, and CSS background images.
```html
```
--------------------------------
### Instance Options
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Details on the available options for initializing Ukiyo.js instances and their default values.
```APIDOC
## Options - Instance Options
```javascript
const parallax = document.querySelector('.image')
new Ukiyo(parallax, {
scale: 1.5, // 1~2 is recommended
speed: 1.5, // 1~2 is recommended
willChange: true,
wrapperClass: "ukiyo-wrapper",
externalRAF: false
})
```
| Option | Type | Default | Description |
| - | - | - | - |
| `scale` | `number` | `1.5` | Parallax image scaling factor. |
| `speed` | `number` | `1.5` | Parallax speed. |
| `willChange` | `boolean` | `false` | When true is specified, the elements will receive will-change: transform when Parallax is active. |
| `wrapperClass` | `string` | `null` | Set any class name to the automatically generated wrapper element. |
| `externalRAF` | `boolean` | `false` | Set it to true if you want to use an external requestAnimationFrame. |
```
--------------------------------
### Usage - JavaScript Initialization
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Demonstrates how to initialize Ukiyo.js with CSS selectors, DOM nodes, or HTMLCollections.
```APIDOC
## Usage - JavaScript
Instantiate Ukiyo with the cool name you gave to the element as the first argument. The element selection supports the following types:
```javascript
// CSS selector
new Ukiyo(".ukiyo")
// or node
const images = document.querySelectorAll(".ukiyo")
new Ukiyo(images)
// or HTMLCollection
const images = document.getElementsByClassName('ukiyo');
new Ukiyo(images);
```
There you go, all set! Now let's see it in action.
```
--------------------------------
### Initialize Ukiyo.js and Lenis
Source: https://github.com/yitengjun/ukiyo-js/blob/main/docs/index.html
Configures Ukiyo.js with external RAF and sets up Lenis for smooth scrolling, synchronized via a single animation frame loop.
```javascript
/** * Ukiyo.js */ const parallax = new Ukiyo('.ukiyo', { externalRAF: true, }); /** * smooth scroll */ const lenis = new Lenis({ duration: 0.75, smoothWheel: true, smoothTouch: false, }); /** * animate */ function raf(time) { parallax.animate(); lenis.raf(time); requestAnimationFrame(raf); } requestAnimationFrame(raf);
```
--------------------------------
### Instantiate Ukiyo
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Initialize Ukiyo using CSS selectors, nodes, or HTMLCollections.
```javascript
// CSS selector
new Ukiyo(".ukiyo")
// or node
const images = document.querySelectorAll(".ukiyo")
new Ukiyo(images)
// or HTMLCollection
const images = document.getElementsByClassName('ukiyo');
new Ukiyo(images);
```
--------------------------------
### Import Ukiyo.js
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Import the library into your project or include it via CDN.
```javascript
import Ukiyo from "ukiyojs";
```
```html
```
--------------------------------
### Constructor: new Ukiyo(elements, options)
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Initializes a new Ukiyo parallax instance. You can pass a CSS selector, HTMLElement, NodeList, or HTMLCollection as the first argument, along with optional configuration options.
```APIDOC
## Constructor: new Ukiyo(elements, options)
### Description
Creates a new Ukiyo parallax instance by passing a CSS selector, HTMLElement, NodeList, or HTMLCollection as the first argument, with optional configuration options.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
import Ukiyo from "ukiyojs";
// Using CSS selector
const parallax = new Ukiyo(".ukiyo");
// Using querySelectorAll
const images = document.querySelectorAll(".parallax-image");
const parallax = new Ukiyo(images);
// Using getElementsByClassName
const elements = document.getElementsByClassName("parallax");
const parallax = new Ukiyo(elements);
// Using a single element
const element = document.querySelector(".hero-image");
const parallax = new Ukiyo(element);
// With full options configuration
const parallax = new Ukiyo(".ukiyo", {
scale: 1.5, // Parallax image scaling factor (default: 1.5, recommended: 1~2)
speed: 1.5, // Parallax animation speed (default: 1.5, recommended: 1~2)
willChange: true, // Enable CSS will-change: transform for better performance (default: false)
wrapperClass: "ukiyo-wrapper", // Custom class for the auto-generated wrapper element
externalRAF: false // Set true to use external requestAnimationFrame (default: false)
});
```
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### Initialize Ukiyo Instance
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Create a new parallax instance using various selector types or full configuration options.
```javascript
import Ukiyo from "ukiyojs";
// Using CSS selector
const parallax = new Ukiyo(".ukiyo");
// Using querySelectorAll
const images = document.querySelectorAll(".parallax-image");
const parallax = new Ukiyo(images);
// Using getElementsByClassName
const elements = document.getElementsByClassName("parallax");
const parallax = new Ukiyo(elements);
// Using a single element
const element = document.querySelector(".hero-image");
const parallax = new Ukiyo(element);
// With full options configuration
const parallax = new Ukiyo(".ukiyo", {
scale: 1.5, // Parallax image scaling factor (default: 1.5, recommended: 1~2)
speed: 1.5, // Parallax animation speed (default: 1.5, recommended: 1~2)
willChange: true, // Enable CSS will-change: transform for better performance (default: false)
wrapperClass: "ukiyo-wrapper", // Custom class for the auto-generated wrapper element
externalRAF: false // Set true to use external requestAnimationFrame (default: false)
});
```
--------------------------------
### Include Ukiyo.js via CDN
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Directly include the library in your HTML file using a script tag.
```html
```
--------------------------------
### Methods - destroy()
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
How to use the `destroy()` method to remove the Ukiyo.js instance.
```APIDOC
## Methods - `destroy()`
Destroy instance:
```javascript
const instance = new Ukiyo(".image")
instance.destroy()
```
```
--------------------------------
### Configure Instance Options
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Customize parallax behavior by passing an options object during instantiation.
```javascript
const parallax = document.querySelector('.image')
new Ukiyo(parallax, {
scale: 1.5, // 1~2 is recommended
speed: 1.5, // 1~2 is recommended
willChange: true,
wrapperClass: "ukiyo-wrapper",
externalRAF: false
})
```
--------------------------------
### Methods - reset()
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
How to use the `reset()` method to recalculate element sizes and positions.
```APIDOC
## Methods - `reset()`
To reset the instance and recalculate the size and position of the elements, use the following code:
```javascript
const instance = new Ukiyo(".image")
instance.reset()
```
```
--------------------------------
### Element Attributes for Options
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
How to set Ukiyo.js options individually for elements using data attributes.
```APIDOC
## Options - Element Attributes
Additionally, you can individually set these options for elements using the `data-u-*` attribute, like this:
```html
```
| Attribute | Values | Description |
| - | - | - |
| `data-u-scale` | `number` | `scale` option. |
| `data-u-speed` | `number` | `speed` option. |
| `data-u-willchange` | | `willChange` option. Just add this to the element to enable it. |
| `data-u-wrapper-class` | `string` | `wrapperClass` option. |
| | | |
> Option names start with `data-u-*`. Don't forget to prefix the option name with a `u` if *u* do.
```
--------------------------------
### Configure Per-Element Options
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Use data attributes to override instance settings for specific elements.
```html
```
--------------------------------
### Set Element Attributes
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Configure options individually on elements using data-u-* attributes.
```html
```
--------------------------------
### Reset and Destroy Ukiyo.js Parallax Instance
Source: https://github.com/yitengjun/ukiyo-js/blob/main/tests/demo/index.html
Provides buttons to reset the parallax effects to their original state or completely destroy the Ukiyo.js instance. This is useful for dynamic content or user interactions.
```javascript
const parallax = new Ukiyo('.ukiyo');
const resetButton = document.querySelector('.button--reset');
const destroyButton = document.querySelector('.button--destroy');
resetButton.addEventListener('click', (event) => {
parallax.reset();
});
destroyButton.addEventListener('click', (event) => {
parallax.destroy();
});
```
--------------------------------
### Reset and Destroy Instances
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Manage instance lifecycle by resetting or destroying the parallax effect.
```javascript
const instance = new Ukiyo(".image")
instance.reset()
```
```javascript
const instance = new Ukiyo(".image")
instance.destroy()
```
--------------------------------
### Define HTML Elements for Parallax
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Apply the ukiyo class to various media elements to enable parallax effects.
```html
```
```html
```
```html
```
```html
```
--------------------------------
### Data Attributes: Per-Element Configuration
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Override instance options on individual elements using `data-u-*` attributes for fine-grained control over each parallax element.
```APIDOC
## Data Attributes: Per-Element Configuration
### Description
Override instance options on individual elements using `data-u-*` attributes for fine-grained control over each parallax element.
### Method
None
### Endpoint
None
### Parameters
None
### Request Example
```html
```
### Response
None
```
--------------------------------
### Use External requestAnimationFrame
Source: https://github.com/yitengjun/ukiyo-js/blob/main/README.md
Manually trigger the animation loop by setting externalRAF to true and calling the animate method.
```javascript
const parallax = new Ukiyo(".ukiyo", {
externalRAF: true
})
function raf(time) {
// animate parallax
parallax.animate()
requestAnimationFrame(raf)
}
requestAnimationFrame(raf)
```
--------------------------------
### Destroy Ukiyo Instance
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Destroys the Ukiyo instance, removing all event listeners, IntersectionObservers, wrapper elements, and inline styles. Use this for cleanup when removing parallax elements or during component unmounting in frameworks.
```javascript
import Ukiyo from "ukiyojs";
const parallax = new Ukiyo(".ukiyo");
// Cleanup when no longer needed
function cleanup() {
parallax.destroy();
}
```
```javascript
import { useEffect, useRef } from "react";
import Ukiyo from "ukiyojs";
function ParallaxComponent() {
const parallaxRef = useRef(null);
useEffect(() => {
// Initialize parallax
parallaxRef.current = new Ukiyo(".ukiyo", {
scale: 1.5,
speed: 1.5
});
// Cleanup on component unmount
return () => {
if (parallaxRef.current) {
parallaxRef.current.destroy();
}
};
}, []);
return ;
}
```
```javascript
import { onMounted, onUnmounted, ref } from "vue";
import Ukiyo from "ukiyojs";
export default {
setup() {
const parallax = ref(null);
onMounted(() => {
parallax.value = new Ukiyo(".ukiyo");
});
onUnmounted(() => {
if (parallax.value) {
parallax.value.destroy();
}
});
}
};
```
--------------------------------
### Trigger Manual Animation
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Use the animate method to integrate with custom requestAnimationFrame loops or third-party libraries.
```javascript
import Ukiyo from "ukiyojs";
// Create parallax with external requestAnimationFrame control
const parallax = new Ukiyo(".ukiyo", {
externalRAF: true
});
// Custom animation loop
function raf(time) {
// Call animate() to update parallax positions
parallax.animate();
requestAnimationFrame(raf);
}
requestAnimationFrame(raf);
// Integration with Lenis smooth scroll library
import Lenis from "@studio-freight/lenis";
const parallax = new Ukiyo(".ukiyo", { externalRAF: true });
const lenis = new Lenis({ duration: 0.75, smoothWheel: true });
function animate(time) {
parallax.animate();
lenis.raf(time);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
```
--------------------------------
### Method: animate()
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Manually triggers the parallax animation. Use this method when `externalRAF` is enabled to integrate with custom animation loops or third-party libraries.
```APIDOC
## Method: animate()
### Description
Manually triggers the parallax animation. Use this method when `externalRAF` is enabled to integrate with custom animation loops or third-party libraries like Lenis or GSAP.
### Method
None
### Endpoint
None
### Parameters
None
### Request Example
```javascript
import Ukiyo from "ukiyojs";
// Create parallax with external requestAnimationFrame control
const parallax = new Ukiyo(".ukiyo", {
externalRAF: true
});
// Custom animation loop
function raf(time) {
// Call animate() to update parallax positions
parallax.animate();
requestAnimationFrame(raf);
}
requestAnimationFrame(raf);
// Integration with Lenis smooth scroll library
import Lenis from "@studio-freight/lenis";
const parallax = new Ukiyo(".ukiyo", { externalRAF: true });
const lenis = new Lenis({ duration: 0.75, smoothWheel: true });
function animate(time) {
parallax.animate();
lenis.raf(time);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
```
### Response
None
```
--------------------------------
### Method: reset()
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Recalculates the size and position of all parallax elements. This is essential to call after dynamic DOM changes, window resizing, or AJAX content loading.
```APIDOC
## reset()
### Description
Recalculates the size and position of all parallax elements. Call this method after dynamic content changes, window resizes that aren't automatically detected, or when the DOM structure is modified.
```
--------------------------------
### Reset Parallax Elements
Source: https://context7.com/yitengjun/ukiyo-js/llms.txt
Call this method after dynamic content changes, window resizes not automatically detected, or when the DOM structure is modified. It recalculates the size and position of all parallax elements.
```javascript
import Ukiyo from "ukiyojs";
const parallax = new Ukiyo(".ukiyo");
// Reset after dynamic content changes
function loadMoreContent() {
// ... add new content to DOM
// Recalculate parallax dimensions
parallax.reset();
}
// Reset after AJAX content load
fetch("/api/images")
.then(response => response.json())
.then(data => {
// Render new images
renderImages(data);
// Reset parallax to include new elements
parallax.reset();
});
// Reset on custom resize handler
window.addEventListener("resize", () => {
// Custom resize logic
adjustLayout();
// Reset parallax calculations
parallax.reset();
});
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.