Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shprink/bttrlazyloading
[Unmaintained] Responsive Lazy Loading plugin for JQuery
https://github.com/shprink/bttrlazyloading
Last synced: 7 days ago
JSON representation
[Unmaintained] Responsive Lazy Loading plugin for JQuery
- Host: GitHub
- URL: https://github.com/shprink/bttrlazyloading
- Owner: shprink
- License: mit
- Created: 2013-10-05T13:32:37.000Z (about 11 years ago)
- Default Branch: develop
- Last Pushed: 2022-08-17T07:25:43.000Z (over 2 years ago)
- Last Synced: 2024-04-13T18:58:29.563Z (7 months ago)
- Language: JavaScript
- Homepage: http://bttrlazyloading.julienrenaux.fr/
- Size: 1.86 MB
- Stars: 412
- Watchers: 33
- Forks: 70
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
BttrLazyLoading.js
==================BttrLazyLoading is a Jquery plugin that allows your web application to defer image loading until images are scrolled to but not only! BttrLazyLoading also allows you to have different version of an image for 4 differents screen sizes: phones (<768px), tablets (≥768px), desktops (≥992px) and large Desktops (≥1200px).
[Demo and Documentation](http://bttrlazyloading.julienrenaux.fr/)
## Installation
BttrLazyLoading depends on jQuery (meaning jQuery must be included before the plugin files) and [Animate.css](https://github.com/daneden/animate.css) (optional) for animations.
```
```
## API
### Options
* delay: Adds delay to the image loading time.
* threshold: By default images are loaded when they appear on the screen. If you want images to load earlier use threshold parameter. Setting threshold to 200 causes image to load 200 pixels before it appears on viewport.
* animation: Adds an animation when the image loads. Animations available: [See list](http://daneden.github.io/animate.css/)
* event: Defines the event that will be use to trigger the image loading/updating.
* placeholder: Base 64 image that is used when the image loads.
* container: You can also use this plugin for images inside scrolling container, such as div with scrollbar. By default the container is the window.
* retina: Enable a better quality on Retina screens. BttrLazyLoading uses a naming convention @2x to display retina's images. BttrLazyLoading will therefore seek for "[email protected]" on retina' screens instead of "yourImage.gif"
* triggermanually: Whether or not to trigger the first image load manually.
* updatemanually: Whether or not to trigger the image update (needed when the window resizes for example) manually.
* backgroundcolor: The background color of your images that are not loaded yet.
* xs: Image Object for Mobile
* sm: Image Object for Tablet
* md: Image Object for Desktop
* lg: Image Object for Large Desktop### Events
* bttrlazyloading.beforeLoad: This event is triggered just before the "bttrlazyloading.load" event.
* bttrlazyloading.load: This event is triggered when the image loading is triggered.
* bttrlazyloading.afterLoad: This event is triggered just after the "bttrlazyloading.load" event.
* bttrlazyloading.error: This event is triggered when none of the images (xs, sm, md and lg) exist. The classic "error" event could therefore be triggered up to 8 times (4 times for a normal screen and 8 times for a retina screen) while "bttrlazyloading.error" will be triggered only once.## Examples
### Set options on instanciation
#### Via data attributes
```
```For a perfect experience 'width' and 'height' are necessary (The plugin cannot know the dimensions of your images before they load.).
```
```or
```
```Only one image size needed! BttrLazyLoading always try to load the biggest version of the image available. Therefore the following example will work on every screen too.
```
```#### Via the instantiation
```
$("#yourImageId").bttrlazyloading({
xs: {
src: "img/720x200.gif",
width: 720,
height: 200
},
sm: {
src: "img/360x200.gif",
width: 360,
height: 200
},
md: {
src: "img/470x200.gif",
width: 470,
height: 200
},
lg: {
src: "img/570x200.gif",
width: 570,
height: 200
},
retina: true,
animation: 'fadeInUp',
delay: 1000,
event: 'click',
container: 'document.body',
threshold: 666,
placeholder: 'test'
})
```## Common problems
### HTML5 Doctype
The HTML5 doctype is require to work correctly.
``````
[More information](http://www.w3schools.com/tags/tag_doctype.asp)
## Support
[![Flattr BttrLazyLoading](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=shprink&url=https%3A%2F%2Fgithub.com%2Fshprink%2FBttrLazyLoading)
## Contribute!
### Issues
Every issue created should have a Codepen to demonstrate the problem.
You can use this Codepen boilerplate: http://codepen.io/shprink/pen/MYbQGR
### Installation
#### Prerequisites
+ [Node JS](http://julienrenaux.fr/2013/05/16/how-to-install-node-js-coffeescript-less-and-uglify-js-on-ubuntu/)
+ [Bower](http://julienrenaux.fr/2013/09/12/bower/)
+ CoffeeScript (Global installation, `$ sudo npm install -g coffee-script`, is optional but convenient in the build step)#### Clone the repository
`$ git clone https://github.com/shprink/BttrLazyLoading`#### Install dependencies
```
$ cd BttrLazyLoading
$ npm install
```### Build
Compiles and minifies BttrLazyLoading.coffee and bttrlazyloading.css.
```
gulp
```
If CoffeeScript isn't globally installed, use `node_modules/.bin/cake build`### Develop
Builds CoffeeScript and CSS, and runs linting and build steps if any changes occur to important files. This allows you to rerun the tests immidiately after you've changed the CoffeeScript, without having to lint and recompile. Of course, any changes that breaks the CoffeeScript will be prompted on the command line.
```
gulp watch (coming)
```### Issues
For any issue a running codepen demonstrating the problem is required. You can fork this one: http://codepen.io/shprink/pen/JoeGPq
### Run tests
Open test/index.htmlYou are now good to go ;)
### Browser Compatibility
IE9+
BttrLazyLoading relies on array.indexOf which was not introduced until IE9. There is a poly fill for this function available here however, it does not help with IE8 support completely.### Contributors
* [Julien Renaux](https://github.com/shprink)
* [Michael Thelin](https://github.com/thelinmichael)