$(document).ready(function(){ if($('.blog-buttons-add-favorite, .performance-vacancy-add-favorite a, .get-list, .main-menu-icons-copy, .blog-buttons-offer, .get-project, .main-menu-icons-home').length>0) { console.log('here'); var overlayLength = $('#overlay').length; $.post("site/forms-modal", function (data) { if ( !overlayLength>0 ){ $("body").append('
'); } $("body").append(data); }).complete(function() { $('.closed-form, #overlay').on('click', function(){ $('#modal_form_favorite, #modal_form_offer, #modal_form_question') .animate({opacity: 0, top: '30%'}, 200, function(){ $(this).css('display', 'none'); $('#overlay').fadeOut(400); } ); }); }); } addToFavorites(); addToOffer(); addCuestions(); function addToFavorites(){ $('.blog-buttons-add-favorite, .performance-vacancy-add-favorite a, .get-list, .main-menu-icons-copy').click(function(e){ var newMarg = $(window).scrollTop(); e.preventDefault() $('#overlay').fadeIn(400, function(){ $('#modal_form_favorite') .css({display:'block', marginTop:-230+newMarg}) .animate({opacity: 1, top: '50%'}, 200); }); }) } function addToOffer(){ $('.blog-buttons-offer, .get-project, .main-menu-icons-home').click(function(e){ var newMarg = $(window).scrollTop(); e.preventDefault() $('#overlay').fadeIn(400, function(){ $('#modal_form_offer') .css({display:'block', marginTop:-313+newMarg}) .animate({opacity: 1, top: '50%'}, 200); }); }) } function addCuestions() { $('.header-contacts-menu li:last-child').click(function(e){ var newMarg = $(window).scrollTop(); e.preventDefault() $('#overlay').fadeIn(400, function(){ $('#modal_form_question') .css({display:'block', marginTop:-230+newMarg}) .animate({opacity: 1, top: '50%'}, 200); }); }) } });