Giter VIP home page Giter VIP logo

simple-lazyload's Introduction

simple-lazyload

一个轻量级懒加载库,支持 imgbackground-imageclass 的懒加载和延时加载。 demo

快速上手

  1. 引入lazyload.js
<script src="./lazyload.js"></script>
  1. 实例化
const lazy = new Lazyload()
  1. set
// 支持 img ( 包含background-image )

lazy.set({
  mode: 'img',
  dataset: 'data-img',
  offset: '50%',  // 支持百分比
  delay: 1000,
})

// 支持 class
lazy.set({
  mode: 'class',
  dataset: 'data-class',
  offset: 200,  // 单位像素
})

以上便是简易教程,非常简单。

  1. 另外,支持链式调用
lazy.set({
  mode: 'img',
  dataset: 'data-img',
  offset: '50%',
  delay: 1000,
}).set({
  mode: 'class',
  dataset: 'data-class',
  offset: '-30%',  // 支持负值
}).set({
  mode: 'img',
  dataset: 'data-img-custom',
  offset: '-30%',
  delay: 0,
})

结语

  • 使用方法到此结束,具体可以参考demo.html
  • 若是好用,欢迎star

Todos

  • 使用Gulp编译出ES5版本。
  • 发布npm包。

simple-lazyload's People

Contributors

iceapriler avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.