Last active
August 29, 2015 14:13
-
-
Save DrewDahlman/d58437615cc3e7a5b891 to your computer and use it in GitHub Desktop.
imgur
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
$(".preload").each( function(){ | |
var image_path = $(this).data('image') | |
$(this).imgur({ | |
img: image_path | |
}, function(el, data){ | |
$(el).css({ | |
'background-image': 'url('+data+)' | |
}) | |
}) | |
}) |
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
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