Skip to content

Instantly share code, notes, and snippets.

@aziz
Created September 23, 2011 12:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aziz/1237256 to your computer and use it in GitHub Desktop.
Save aziz/1237256 to your computer and use it in GitHub Desktop.
jQuery Image Wrapper
$(document).ready(function(){
$("img").load(function() {
$(this).wrap(function(){
return '<span class="image-wrap ' + $(this).attr('class') + '" style="position:relative; display:inline-block; background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
});
$(this).css("opacity","0");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment