Лучшее решение, исключающее прыжки наверх при закрытии всплывающего окна:
$(document).ready(function(){
var targetNodes = $(".cg-popup");
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var myObserver = new MutationObserver (mutationHandler);
var obsConfig = { attributes : true, attributeFilter : ['style'] };
// ADD A TARGET NODE TO THE OBESERVER. CAN ONLY ADD ONE NODE AT TIME
targetNodes.each ( function () {
myObserver.observe (this, obsConfig);
} );
function mutationHandler (mutationRecords) {
var activate_scroll = true;
$(".cg-popup").each(function( index ) {
if($(this).css("display") != "none"){
$('html, body').css({'overflow-y': 'hidden', 'height': '100%'});
activate_scroll = false;
return;
}
});
if(activate_scroll){
$('html, body').css({'overflow-y': 'auto', 'height': 'auto'});
}
}
});