Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🪧 Universal lazy loading library for placeholder images leveraging native browser APIs

License

NotificationsYou must be signed in to change notification settings

johannschopplich/unlazy

Repository files navigation

unlazy library

unlazy

npm versionbundle

Universal lazy loading library leveraging native browser APIs. It is intended to be used with theloading="lazy" attribute alongside (blurry) placeholder images and with aBlurHash orThumbHash string.

Features

  • 🎀Native: Utilizes theloading="lazy" attribute
  • 🎛️Framework-agnostic: Works with any framework or no framework at all
  • 🌊BlurHash & ThumbHash support: SSR & client-sideBlurHash andThumbHash decoding
  • 🪄Sizing: Automatically calculates thesizes attribute
  • 🔍SEO-friendly: Detects search engine bots and preloads all images
  • 🎟<picture>: Supports multiple image tags
  • 🏎Auto-initialize: Usable without a build step

Setup

📖 Read the documentation

# pnpmpnpm add -D unlazy# npmnpm i -D unlazy

Basic Usage

📖 Read the documentation

To apply lazy loading to all images with theloading="lazy" attribute, import thelazyLoad function and call it without any arguments:

import{lazyLoad}from'unlazy'// Apply lazy loading for all images by the selector `img[loading="lazy"]`lazyLoad()

You can target specific images by passing a CSS selector, a DOM element, a list of DOM elements, or an array of DOM elements to lazy-load tolazyLoad.

💻 Development

  1. Clone this repository
  2. EnableCorepack usingcorepack enable
  3. Install dependencies usingpnpm install
  4. Runpnpm run dev:prepare
  5. Start development server usingpnpm run dev inside the one of thepackages directories

License

MIT License © 2023-PRESENTJohann Schopplich


[8]ページ先頭

©2009-2025 Movatter.jp