• Stars
    star
    231
  • Rank 168,091 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A jQuery plugin provides a lazyload function for images, iframe or anything.

jQuery-lazyload-any

A jQuery plugin provides a lazyload function for images, iframe or anything.
NPM

Demo

Images (Overflow and Tabs)
Youtube

Download

Compress
Uncompress

Installation

You can install jquery-lazyload-any by using Bower.

bower install jquery-lazyload-any

For node.js, you can use this command to install:

npm install jquery-lazyload-any

Usage

HTML
Attribute Style

<div id="you-want-lazyload" data-lazyload="&lt;p&gt;Anything you want to lazyload&lt;/p&gt;">
</div>

Script Style

<div id="you-want-lazyload">
  <script type="text/lazyload">
    <p>Anything you want to lazyload</p>
  </script>
</div>

Comment Style

<div id="you-want-lazyload">
  <!--
    <p>Anything you want to lazyload</p>
  -->
</div>

JavaScript

$('#you-want-lazyload').lazyload(options);

You should choose only one style. When multiple styles set, priority is Attribute > Script > Comment.

Options

threshold: Number (default: 0)

Sets the pixels to load earlier. Setting threshold to 200 causes image to load 200 pixels before it appears on viewport. It should be greater or equal zero.

load: Function(element) (default: undefined)

Sets the callback function when the load event is firing.

element: The content in lazyload tag will be returned as a jQuery object.

trigger: String (default: "appear")

Sets events to trigger lazyload. Default is customized event appear, it will trigger when element appear in screen. You could set other events including each one separated by a space, ex: mousedown touchstart.

Methods

$.lazyload.check()

Force to trigger detection event.

$.lazyload.setInterval(inverval)

Set interval of timer that check container display status.

inverval: Number (default: 50)

Interval of timer. Set 0 to disable timer, and you can use $.lazyload.check() to trigger detection manually.

$.lazyload.refresh(selector)

Refresh status of elements bound event. Element will bind scroll event to parent scrollable automatically when initializing as lazyload. If you move element, you should use this method to bind again.

selector: String or Object (default: undefined)

The elements that you want to refresh. It will refresh all lazyload elements if you don't pass this parameter.

Notice

  • You should initialize after the element add to page. Or it can't detect whether it's in screen. If you do that, you still can use $.lazyload.check() to force detection.
  • Detection uses jQuery element.is(':visible'), it will return false if element's width and height are equal to zero. So you have to make sure the lazyload element with any width or height.

Example

HTML

<div class="lazyload">
  <!--
    <img src="image.png" />
  -->
</div>

JavaScript

$('.lazyload').lazyload({
  // Sets the pixels to load earlier. Setting threshold to 200 causes image to load 200 pixels
  // before it appears on viewport. It should be greater or equal zero.
  threshold: 200,

  // Sets the callback function when the load event is firing.
  // element: The content in lazyload tag will be returned as a jQuery object.
  load: function(element) {},

  // Sets events to trigger lazyload. Default is customized event `appear`, it will trigger when
  // element appear in screen. You could set other events including each one separated by a space.
  trigger: "appear"
});

License

The project is released under the MIT license.

Contact

The project's website is located at https://github.com/emn178/jquery-lazyload-any
Author: Yi-Cyuan Chen ([email protected])

More Repositories

1

js-sha256

A simple SHA-256 / SHA-224 hash function for JavaScript supports UTF-8 encoding.
JavaScript
824
star
2

js-md5

A simple MD5 hash function for JavaScript supports UTF-8 encoding.
JavaScript
750
star
3

online-tools

Online tools provides md2, md5, sha1, sha2, sha512, bas64, html encode / decode functions
HTML
657
star
4

chartjs-plugin-labels

Plugin for Chart.js to display percentage, value or label in Pie or Doughnut.
JavaScript
597
star
5

js-sha3

A simple SHA-3 / Keccak hash function for JavaScript supports UTF-8 encoding.
JavaScript
337
star
6

js-sha1

A simple SHA1 hash function for JavaScript supports UTF-8 encoding.
JavaScript
329
star
7

js-sha512

A simple SHA-512, SHA-384, SHA-512/224, SHA-512/256 hash functions for JavaScript supports UTF-8 encoding.
JavaScript
216
star
8

markdown

A markdown example shows how to write a markdown file.
108
star
9

angular2-chartjs

Chart.js component for Angular2
TypeScript
95
star
10

jquery-stickit

A jQuery plugin provides a sticky header, sidebar or else when scrolling.
JavaScript
76
star
11

hi-base64

A simple Base64 encode / decode function for JavaScript supports UTF-8 encoding.
JavaScript
70
star
12

hi-base32

A simple Base32(RFC 4648) encode / decode function for JavaScript supports UTF-8 encoding.
JavaScript
56
star
13

js-htmlencode

A simple HTML encode / decode function for JavaScript.
JavaScript
54
star
14

js-crc

Simple CRC checksum functions for JavaScript(CRC-16 and CRC-32).
JavaScript
33
star
15

solidity-optimize-name

Find a optimized name for method.
JavaScript
31
star
16

jquery-animations

A CSS3 animation framework based on jQuery providing an easy way to develop cross browser CSS3 animations.
JavaScript
30
star
17

jquery-animations-tile

A plugin of jQuery-animations that provides tile animations.
JavaScript
22
star
18

jquery-appear

A jQuery plugin provides appear and disappear events to do lazyload, infinite scroll or else effect.
JavaScript
16
star
19

color-sampler

A jQuery plugin provides color sampler function for Canvas.
JavaScript
15
star
20

js-throttle-debounce

A javascript prototype plugin provides throttle and debounce methods.
JavaScript
15
star
21

jquery-animations-spotlight

A plugin of jQuery-animations that provides spotlight animations.
JavaScript
13
star
22

js-md4

A simple MD4 hash function for JavaScript supports UTF-8 encoding.
JavaScript
9
star
23

angular2-justgage

JustGage component for Angular2
TypeScript
6
star
24

angular-appear

An AngularJS plugin provides appear and disappear events to do infinite scroll or else effect.
6
star
25

js-md2

A simple MD2 hash function for JavaScript supports UTF-8 encoding.
JavaScript
4
star
26

blog

emn178's blog.
4
star
27

zipacker

Zip and download files in client side.
JavaScript
3
star
28

rails-intl-tel-input

Integrate with intl-tel-input to provide international telephone numbers input and form helper.
JavaScript
2
star
29

jquery-mscroll

A jQuery plugin enables to force to fire scroll event in mobile devices.
JavaScript
2
star
30

angular2-chartjs-sample

TypeScript
2
star
31

angular-marquee

An angular plugin provides marquee message.
2
star
32

sms_carrier

SMS Carrier is a framework for designing SMS service layers.
Ruby
2
star
33

sendcloud-mailer

An Action Mailer delivery method for SendCloud email service.
Ruby
2
star
34

devise_mobile_confirmable

It adds support to devise for confirming users' mobile by SMS.
Ruby
2
star
35

tem

1
star
36

Chart.Crosshairs.js

Crosshairs plugin for Chart.js.
JavaScript
1
star
37

chain-network

JavaScript
1
star
38

angular-bind-compile

An angular plugin provides bind html with compilation.
1
star
39

twilio-carrier

An sms_carrier delivery method for Twilio SMS service.
Ruby
1
star
40

chain-decoder

CSS
1
star
41

presenters

A simple presenter pattern for ruby. It also can work in rails.
Ruby
1
star
42

faye-jwt

A gem that provides authentication by JWT(json web token) with faye.
Ruby
1
star
43

flash-messenger

A jQuery plugin provides a simple flash messages and interface.
JavaScript
1
star
44

typescript-package-sample

Show you how to write a TypScript package.
TypeScript
1
star
45

fakesite-wechat

A fakesite plugin that provides a stub method for wechat. It's useful to bypass oauth flow in develpment environment.
Ruby
1
star