Skip to content

Instantly share code, notes, and snippets.

@sukhikh18
Last active February 15, 2019 05:49
Show Gist options
  • Save sukhikh18/121ba5f45d47736c7b35d1bda7e65739 to your computer and use it in GitHub Desktop.
Save sukhikh18/121ba5f45d47736c7b35d1bda7e65739 to your computer and use it in GitHub Desktop.
Easy fancybox preloader
var preloaderClass = 'fb-loading';
window.showPreloader = function( message ) {
if(!message) message = 'Загрузка..';
$preload = $('<p>'+ message +'</p>').css({
'margin-top': '50px',
'margin-bottom': '-40px',
'padding-bottom': '',
'color': '#ddd'
});;
var $body = $('body');
$.fancybox.open({
content : $preload,
type : 'html',
smallBtn : false,
afterLoad: function(instance, current) {
$('.fancybox-content', instance.$refs['fancybox-stage']).css('background', 'none');
},
afterShow: function(instance, current) {
$body.addClass(preloaderClass);
instance.showLoading( current );
},
afterClose: function(instance, current) {
$body.removeClass(preloaderClass);
instance.hideLoading( current );
}
});
};
window.hidePreloader = function() {
var $body = $('body');
if( $body.hasClass(preloaderClass) ) {
$.fancybox.getInstance().close();
}
};
showPreloader( 'What is love?' );
setTimeout(function() {
hidePreloader();
$.fancybox.open({
content : 'Hello world!',
type : 'html',
});
}, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment