Skip to content

Instantly share code, notes, and snippets.

@emersonbroga
Created September 19, 2013 05:00
Show Gist options
  • Save emersonbroga/6619288 to your computer and use it in GitHub Desktop.
Save emersonbroga/6619288 to your computer and use it in GitHub Desktop.
Change gifs with placeholder to improve page speed and reduce load time.
$("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