Skip to content

Instantly share code, notes, and snippets.

@AstakhovArtem
Created April 30, 2014 12:53
Show Gist options
  • Save AstakhovArtem/10373fa0ecc3e1f07725 to your computer and use it in GitHub Desktop.
Save AstakhovArtem/10373fa0ecc3e1f07725 to your computer and use it in GitHub Desktop.
function($) {
/**
* Show preloader under element
*
* @param {string} height of preloader block
* @param {string} width of preloader block
* @return {void}
*/
$.fn.showPreloader = function(width, height) {
width = width || '100%';
height = height || '100%';
return this.each(function() {
var blockEl = $(this);
if (blockEl.css('position') == 'static') {
blockEl.css('position', 'relative');
}
if (blockEl.css('display') != 'inline' ||
blockEl.css('display') != 'inline-block'
) {
blockEl.attr('display_old', blockEl.css('display'));
blockEl.css('display', 'block');
}
blockEl.prepend(
$('<div>', {
'class': 'preloaders',
height: height,
width: width
})
);
});
};
/**
* Remove preloader
*
* @return {void}
*/
$.fn.removePreloader = function() {
return this.each(function() {
var blockEl = $(this);
var preloaders = blockEl.children('.preloaders');
if (blockEl.attr('display_old')) {
blockEl.css('display', blockEl.attr('display_old'));
blockEl.removeAttr('display_old');
}
preloaders.remove();
});
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment