Skip to content

Instantly share code, notes, and snippets.

@tayvano
Last active April 5, 2017 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tayvano/8bcd4a364c38efe0926d0db313f9351e to your computer and use it in GitHub Desktop.
Save tayvano/8bcd4a364c38efe0926d0db313f9351e to your computer and use it in GitHub Desktop.
<div class="lazyImg lazyImg--notloaded" style="background-image: url(<?php echo $hero_bg['sizes']['lazyImg']?>)" data-image="<?php echo $hero_bg['sizes']['hero-bg']?>"></div>
<noscript><div style="background-image: url(<?php echo $hero_bg['sizes']['hero-bg']?>)"></div></noscript>
function loadLazyImg() {
$.each( $('.lazyImg'), function(index, val) {
var img = new Image()
var src = $(this).attr('data-image')
img.src = src
var image = $(this)
img.onload = function() {
image.css('background-image', 'url(' + src + ')')
image.removeClass('lazyImg--notloaded')
image.removeAttr('data-image')
}
})
},
.lazyImg {
transition: filter 300ms ease-in-out, transform 300ms ease-in-out;
}
.lazyImg--notloaded {
filter: blur(9px);
transform: scale(1.02);
}
.no-js .lazyImg--notloaded {
display: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment