Created
September 19, 2013 05:00
-
-
Save emersonbroga/6619288 to your computer and use it in GitHub Desktop.
Change gifs with placeholder to improve page speed and reduce load time.
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
$("img").each(function(index, value){ | |
var $img = $(value), | |
src = $img.attr('src'), | |
w = 0; | |
h = 0; | |
if( src.search('.gif') !== -1){ | |
w = $img.width(); | |
h = $img.height(); | |
$img.attr('src', 'http://placehold.it/'+w+'x'+h+'&text=GIF'); | |
$img.attr('data-gif', src); | |
$img.addClass('gif'); | |
} | |
}); | |
$('.gif').hover(function() { | |
var src = $(this).attr('data-gif'), | |
placeholder = $(this).attr('src'); | |
$(this).attr('src', src); | |
$(this).removeClass('gif'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment