This time I will share jQuery Plugin and tutorial about Retina-ready Responsive Image Plugin For jQuery, hope it will help you in programming stack.
Just another jQuery based retina-ready responsive image solution that helps you load in proper images dynamically for different screen sizes, depending on the viewport or parent container’s width.
Basic usage:
1. Include jQuery library and the jQuery Responsive Image plugin on the html page.
1 |
< script src = "//code.jquery.com/jquery-1.11.3.min.js" ></ script > |
2 |
< script src = "jquery.responsiveImage.js" ></ script > |
2. Include the jQuery debouncedresize plugin to load in images dynamically once after a window resize.
1 |
< script src = "jquery.debouncedresize.js" ></ script > |
3. Insert images with different resolutions into the container using data-src
attribute. Breakpoints start from 0px to 399px, 400px to 599px, 600px to 799px, 800px to 999px and large image above 1000px.
1 |
< span class = "picture" data-alt = "foo" data-title = "bar" data-class = "img-responsive" > |
2 |
< span data-src = "400x200.jpg" ></ span > |
3 |
< span data-src = "600x300.jpg" data-min-width = "400" ></ span > |
4 |
< span data-src = "800x400.jpg" data-min-width = "600" ></ span > |
5 |
< span data-src = "1000x500.jpg" data-min-width = "800" ></ span > |
6 |
< span data-src = "1200x600.jpg" data-min-width = "1000" ></ span > |
4. Initialize the responsive image plugin.
1 |
$( '.picture' ).responsiveImage(); |
5. Default settings.
01 |
$( '.picture' ).responsiveImage({ |
15 |
attributes: [ 'title' , 'alt' , 'class' , 'width' , 'height' ], |
20 |
resizeEvent: 'resize ', |
22 |
// Preload images before loading them into the DOM. |
25 |
// Automatically include dpr on best fit width calculation. |
28 |
// The viewport and the container width are calculated automatically. |
29 |
// The callback function can be used for any custom width calculation. |
30 |
// Inside this function you can use the plugins' context. |
37 |
maxWidthDefault: Number.MAX_VALUE, |
6. Events.
- ready.responsiveImage: fires when the responsive image was initially loaded, fires only once
- all.ready.responsiveImage: fires when all responsive images were initially loaded, fires only once
- new.source.responsiveImage: fires when the image was inserted into the DOM
- load.source.responsiveImage: fires when the image source was loaded
Changelog:
v1.6.0 (2018-09-18)
- added image load error handling and documented optional <img> tag as fallback
v1.5.0 (2017-12-03)
- added load.responsiveImage event listener
v1.4.3 (2017-09-26)
- removed off() from image load
v1.4.1 (2016-04-06)
- fixed min-dpr result to 1 because of lower dpr values on zoomed sites
v1.4.0 (2016-02-10)
- added sourcePrefix option
v1.3.1 (2016-02-01)
- added option to disable resize event
2015-12-10
- added events for ready, all.ready
- added load event to newly created image
2015-07-06
- refactored attribute injection to be configurable
This awesome jQuery plugin is developed by janrembold. For more Advanced Usages, please check the demo page or visit the official website.