tada

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

  • Owner: fallroot/tada
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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.

Main metrics

Overview
Name With Ownerfallroot/tada
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2015-03-12 20:47:02
Pushed At2022-11-16 23:25:52
Last Commit At2021-03-09 11:24:10
Release Count5
Last Release Namev0.2.2 (Posted on 2018-10-04 12:42:20)
First Release Namev0.0.1 (Posted on 2015-03-13 13:34:02)
用户参与
Stargazers Count114
Watchers Count10
Fork Count12
Commits Count21
Has Issues Enabled
Issues Count3
Issue Open Count3
Pull Requests Count9
Pull Requests Open Count8
Pull Requests Close Count4
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private