Skip to content

Instantly share code, notes, and snippets.

@DrewDahlman
Last active August 29, 2015 14:13
Show Gist options
  • Save DrewDahlman/d58437615cc3e7a5b891 to your computer and use it in GitHub Desktop.
Save DrewDahlman/d58437615cc3e7a5b891 to your computer and use it in GitHub Desktop.
imgur
$(".preload").each( function(){
var image_path = $(this).data('image')
$(this).imgur({
img: image_path
}, function(el, data){
$(el).css({
'background-image': 'url('+data+)'
})
})
})
jQuery(function($) {
$.fn.imgur = function(options, loaded) {
var defaults = {
img: ''
}
if (loaded) {
var callback = {
loaded: loaded
}
}
return this.each(function() {
var settings = $.extend(defaults, options);
var callbacks = $.extend(callback, loaded);
var $this = $(this);
function init() {
if (callbacks.loaded != null) {
var _image = new Image();
_image.onLoad = loaded();
_image.src = settings.img;
}
}
function loaded() {
if (callbacks.loaded != null) {
callbacks.loaded($this, settings.img);
}
}
init();
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment