Created
January 25, 2018 07:31
-
-
Save webdevsuperfast/79194c679e5274d9191656ea63d5711a to your computer and use it in GitHub Desktop.
Preload images
This file contains hidden or 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
| // @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