Created
June 7, 2013 05:18
-
-
Save joho/5727195 to your computer and use it in GitHub Desktop.
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
// LAZY IMAGE LOADING FOR RESPONSIVE | |
var lazyImageLoad = function () { | |
$('.lazy-image-container').each(function (index) { | |
var thisElement, | |
noScriptElement, | |
imgElement; | |
thisElement = $(this); | |
if (!thisElement.parent().is(':hidden')) { | |
noScriptElement = thisElement.find("noscript"); | |
if (noScriptElement.size() > 0) { | |
thisElement.append(noScriptElement.text()); | |
noScriptElement.remove(); | |
} | |
thisElement.removeClass("lazy-image-container"); | |
} | |
}); | |
} | |
// fire once on page load. no need to wait for domReady because we | |
// load this script at the end of the page | |
lazyImageLoad(); | |
// register the function to run every time a new breakpoint matches | |
// on a media query. the timeout is important as you need to wait | |
// for a browser repaint to check visibility of elements. | |
if (typeof(metaQuery) !== 'undefined') { | |
metaQuery.bindGlobal(function () { | |
setTimeout(lazyImageLoad, 0); | |
}); | |
} |
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
<a href="#" class="lazy-image-container"> | |
<!--[if gt IE 8]><!--><noscript><!--<![endif]--> | |
<img alt="some alt" src="some_image.jpg" /> | |
<!--[if gt IE 8]><!--></noscript><!--<![endif]--> | |
</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment