0.2.4 • Published 6 years ago

@fallroot/tada v0.2.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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

namedefaultunitdescription
attributedata-srcattribute name for image url
delay50millisecondsdelay for scroll event activation
threshold20%% or px. px can be omittedmargin for early loading
callbackfunction(element) {}callback after image loaded.

Browser compatibility

Internet Explorer 9+ and other major browsers are supported.

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

8 years ago