tada

Lightweight, no dependency library for lazy image load. Duplicate element check, throttled scroll handler, percent threshold supported.

  • 所有者: fallroot/tada
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

TADA

Lightweight, no dependency library for lazy image load.

Features

  • Uses IntersectionObserver API
  • Duplicate element check
  • Debounced event handler
  • Percentage threshold

Usage

Use data-src attribute for actual image. This attribute name can be changed by calling Tada.setup method.
If that attribute is used in non <img> tag, image will be background image.

<img src="placeholder.png" data-src="original.png">

<div data-src="background.png"></div>
/* CSS selector */
Tada.add('ul img')

/* HTML element */
var img = document.createElement('img')
img.setAttribute('src', 'placeholder.png')
img.setAttribute('data-src', 'original.png')

Tada.add(img)

/* In jQuery */
$.fn.tada = function () {
  return this.each(function () {
    Tada.add(this)
  })
}

$('img').tada()

Settings

If you want to change default settings, call Tada.setup method before using Tada.add.

Tada.setup({
  attribute: 'data-src',
  delay: 50,
  threshold: '20%',
  callback: function (element) {
    console.log(element)
  }
})

Tada.add(element)

Options

name, default, unit, description
----, -------, ----, -----------
attribute, data-src, attribute name for image url
delay, 50, milliseconds, delay for scroll event activation
threshold, 20%, % or px. px can be omitted, margin for early loading
callback, function(element) {}, callback after image loaded.

Browser compatibility

Internet Explorer 9+ and other major browsers are supported.

主要指标

概览
名称与所有者fallroot/tada
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2015-03-12 20:47:02
推送于2022-11-16 23:25:52
最后一次提交2021-03-09 11:24:10
发布数5
最新版本名称v0.2.2 (发布于 2018-10-04 12:42:20)
第一版名称v0.0.1 (发布于 2015-03-13 13:34:02)
用户参与
星数114
关注者数10
派生数12
提交数21
已启用问题?
问题数3
打开的问题数3
拉请求数9
打开的拉请求数8
关闭的拉请求数4
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?