Created
October 3, 2012 22:55
-
-
Save ncherro/3830417 to your computer and use it in GitHub Desktop.
Simple jquery plugin fades image in on load
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
(function($) { | |
var PrettyLoader = function(el, opts) { | |
var settings = $.extend({}, $.fn.prettyloader.defaults, opts) | |
$el = $(el); | |
function init() { | |
$el.hide().one('load', loaded).each(function() { | |
// manually call load() if the image has been cached | |
if (this.complete) $el.load(); | |
}); | |
} | |
function loaded() { | |
$el.fadeIn(settings.transition); | |
} | |
init(); | |
}; | |
$.fn.prettyloader = function(options) { | |
return this.each(function(idx, el) { | |
var $el = $(this), key = 'prettyloader'; | |
if ($el.data(key)) { return; } | |
var prettyloader = new PrettyLoader(this, options); | |
$el.data(key, prettyloader); | |
}); | |
}; | |
$.fn.prettyloader.defaults = { | |
transition: 300 | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment