百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
U

ukiyo-js

> 编程语言
开源

⛰️ 动态、现代且高效的背景平行移动效果。

374 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

⛰️ 动态、现代且高效的背景平行移动效果。

⛰️ Features

  • ️ Background parallax for , , `````` and background-image
  • Efficient and dynamic animations
  • No dependencies
  • TypeScript support

Installation

Install ukiyojs using your package manager of choice.

bash
# npm
npm install ukiyojs

# yarn
yarn add ukiyojs

# pnpm
pnpm add ukiyojs

Import Ukiyo:

javascript
import Ukiyo from "ukiyojs";

or import via CDN:

xml

️ Usage

HTML

Give the elements cool names like ukiyo to call them in scripts for parallax effects.

  • ``````

xml
  • ``````
xml

  
  
  
  • ``````
xml
  • ️ CSS background-image
xml

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.

⚙️ 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.

Element attributes

Additionally, you can individually set these options for elements using the data-u-* attribute, like this:

xml
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.


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.

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()
  • destroy()

Destroy instance:

javascript
const instance = new Ukiyo(".image")

instance.destroy()

Notes

When using Lenis in combination

  • As of July 2023, we have identified a bug in Safari when using it in conjunction with Lenis, which causes parallax effects to become distorted during scrolling. This issue is due to a bug in Safari itself. To address this bug, you may need to apply styles like pointer-events: none; to the parallax elements, preventing scroll events from affecting them. However, please be cautious as this may disable interaction events for those elements.

    • https://github.com/studio-freight/lenis/issues/187

️ Browser Support

IE Edge Firefox Chrome Opera Safari iOS Safari
❌No Support ✅Latest ✅Latest ✅Latest ✅Latest ✅Latest ✅Latest

Parallax animations are automatically disabled in browsers that do not support them.

️ Examples

How is Ukiyo being used?

  • UKIYO - from @yitengjun
  • YTNG - Portfolio - from @yitengjun

License

MIT License

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptbackground-parallaxeffectsparallaxparallax-scrolling

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言