Last active
February 15, 2019 05:49
-
-
Save sukhikh18/121ba5f45d47736c7b35d1bda7e65739 to your computer and use it in GitHub Desktop.
Easy fancybox preloader
This file contains hidden or 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
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