-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aFarkas
committed
Nov 18, 2014
1 parent
516c4b1
commit 25cd929
Showing
4 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* effect plugin for lazySizes: | ||
* | ||
* Usage: | ||
* | ||
* 1. fadein after loading: | ||
* | ||
img.lazyload, | ||
img.lazyloading { | ||
opacity: 0; | ||
} | ||
img.lazyloaded { | ||
opacity: 1; | ||
transition: opacity 300ms; | ||
} | ||
* | ||
* 2. fadein while loading: | ||
* | ||
img.lazyload { | ||
opacity: 0; | ||
} | ||
img.lazyloading { | ||
opacity: 1; | ||
transition: opacity 300ms; | ||
} | ||
*/ | ||
|
||
(function(window, document){ | ||
'use strict'; | ||
var config, animEvent; | ||
|
||
if(document.addEventListener){ | ||
config = window.lazySizesConfig || (window.lazySizes && lazySizes.cfg); | ||
animEvent = 'onwebkitanimationend' in window ? 'webkitanimationend' : 'animationend'; | ||
|
||
if(!config){ | ||
config = {}; | ||
window.lazySizesConfig = config; | ||
} | ||
|
||
if(!('loadingClass' in config)){ | ||
config.loadingClass = 'lazyloading'; | ||
} | ||
if(!('loadedClass' in config)){ | ||
config.loadedClass = 'lazyloaded'; | ||
} | ||
|
||
|
||
|
||
document.addEventListener('lazybeforeunveil', function(e){ | ||
if(!e.defaultPrevented && e.target.nodeName.toUpperCase() == 'IMG' && lazySizes.aC) { | ||
|
||
e.target.addEventListener('load', onLoad, false); | ||
e.target.addEventListener('error', onLoad, false); | ||
if(config.loadingClass){ | ||
lazySizes.aC(e.target, config.loadingClass); | ||
} | ||
} | ||
}, false); | ||
|
||
} | ||
|
||
function removeLoadedClass(e){ | ||
e.target.removeEventListener('transitionend', removeLoadedClass, false); | ||
e.target.removeEventListener(animEvent, removeLoadedClass, false); | ||
lazySizes.rC(e.target, config.loadedClass); | ||
} | ||
|
||
function onLoad(e){ | ||
e.target.removeEventListener('load', onLoad, false); | ||
e.target.removeEventListener('error', onLoad, false); | ||
if(config.loadingClass){ | ||
lazySizes.rC(e.target, config.loadingClass); | ||
} | ||
if(config.loadedClass){ | ||
e.target.addEventListener('transitionend', removeLoadedClass, false); | ||
e.target.addEventListener(animEvent, removeLoadedClass, false); | ||
lazySizes.aC(e.target, config.loadedClass); | ||
} | ||
} | ||
|
||
|
||
})(window, document); |