Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ How to Use

LazyLoad should be initialized during the DOMReady event. There are no required arguments -- only options.

#JS
# JS With Load Trigger on Scroll
/* LazyLoad instance */
var lazyloader = new LazyLoad({
range: 200,
Expand All @@ -21,6 +21,15 @@ LazyLoad should be initialized during the DOMReady event. There are no required
container: window
});

# JS With Manual Load Trigger
var lazyLoader = new LazyLoad({
container: window,
elements: 'img',
useScrollLoad: false
});

lazyLoader.manualLoad()

#HTML
<img src="http://davidwalsh.name/dw-content/blank.gif" data-src="http://davidwalsh.name/dw-content/mexico-2009/small/102_1152.jpg" />
<!-- or -->
Expand Down
27 changes: 22 additions & 5 deletions Source/LazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var LazyLoad = new Class({
container: window,
mode: "vertical",
realSrcAttribute: "data-src",
useFade: true
useFade: true,
useScrollLoad: true
},

/* initialize */
Expand All @@ -39,9 +40,25 @@ var LazyLoad = new Class({
this.container = document.id(this.options.container);
this.elements = document.id(this.container == window ? document.body : this.container).getElements(this.options.elements);

// Set a variable for the "highest" value this has been
this.largestPosition = 0;

if(this.options.useScrollLoad) {
// Set a variable for the "highest" value this has been
this.largestPosition = 0;

this.scrollLoad();
} else {
if(this.options.useFade) {
this.elements.each(function(el) {
el.setStyle('opacity', 0);
});
}
}
},
manualLoad: function() {
this.elements.each(function(img) {
this.loadImage(img);
}, this);
},
scrollLoad: function() {
// Figure out which axis to check out
var axis = (this.options.mode == "vertical" ? "y": "x");

Expand Down Expand Up @@ -101,7 +118,7 @@ var LazyLoad = new Class({
}.bind(this);

// Add scroll listener
this.container.addEvent("scroll", action);
this.container.addEvent("scroll", action);
},
loadImage: function(image) {
// Set load event for fadeIn
Expand Down