Приклеиваем блок
function me_sticky() {
console.log('Sticky!');
var windowWidth = window.innerWidth;
var addBlock = $('#calc-form-2');
var endBlock = $('.site-footer');
var containerWidth = $('#calc-form-2').width() + 20;
var containerWidth1 = $('#calc-form-1').width() + 20;
// var marginRight = ( windowWidth - containerWidth - 540 ) / 2;
var marginRight = ( windowWidth - containerWidth - containerWidth1 ) / 2;;
// addBlock.style.marginRight = marginRight + "px";
if ( null != addBlock ) {
var addBlockTopPos = addBlock.offset().top;
var addBlockHeight = addBlock.height();
var endBlockTopPos = endBlock.offset().top;
var stopPos = endBlockTopPos - addBlockHeight + addBlockTopPos - 5;
var topPos = stopPos + 60;
window.onscroll = function() {
var scrollHeight = Math.max( document.documentElement.scrollHeight, document.documentElement.clientHeight);
var wst = $(window).scrollTop();
console.log('wst :' + wst);
if ( addBlockTopPos < wst ) {
addBlock.css('position', 'fixed').css('top', '10px').css('right', marginRight).css('width', containerWidth);
// addBlock.css('position', 'fixed');
} else {
addBlock.css('top', 'auto').css('right', marginRight).css('width', containerWidth);;
addBlock.css('position', 'absolute');
}
if ( wst > stopPos ) {
addBlock.css('top', stopPos);
addBlock.css('position', 'absolute');
}
}
}
}