Skip to content

Instantly share code, notes, and snippets.

@webdevsuperfast
Created January 25, 2018 07:31
Show Gist options
  • Select an option

  • Save webdevsuperfast/79194c679e5274d9191656ea63d5711a to your computer and use it in GitHub Desktop.

Select an option

Save webdevsuperfast/79194c679e5274d9191656ea63d5711a to your computer and use it in GitHub Desktop.
Preload images
// @link http://jsfiddle.net/andyshora/5YVNN/
// @link http://andyshora.com/css-image-container-padding-hack.html
$(document).ready(function() {
// when the image has loaded
$('.image').load(function() {
// remove loading class from the wrapper
$(this).parent('.image-wrapper--loading').removeClass('image-wrapper--loading');
});
var imagePath = 'http://andyshora.com/assets/img/pages/grumpy-cat.jpg';
// delaying the loading of the image so you can see the loading state
$('.load-image').click(function() {
$('.image').attr('src', imagePath + '?' + Math.random());
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment