Skip to content

Instantly share code, notes, and snippets.

@nicco88
Created February 7, 2017 08:34
Show Gist options
  • Save nicco88/e127ce43b45fc192109d97106493e921 to your computer and use it in GitHub Desktop.
Save nicco88/e127ce43b45fc192109d97106493e921 to your computer and use it in GitHub Desktop.
var anchored = false,
bodyH = document.querySelector('body').offsetHeight,
footerH = document.querySelector('footer').offsetHeight,
indexadv = document.querySelector('.indexadv'),
indexadvH = indexadv.offsetHeight;
var indexadvFixedBottom = indexadv.getBoundingClientRect().bottom;
var breaking = bodyH - indexadvFixedBottom - footerH - 35;
var indexadvTop = bodyH - footerH - indexadvH;
window.onscroll = function() {
// var windowH = window.outerHeight;
// var indexadvFixedTop = parseInt(window.getComputedStyle(indexadv, null).getPropertyValue('top'));
if (window.pageYOffset > breaking && anchored === false) {
anchored = true;
console.log('down');
indexadv.style.position = 'absolute';
indexadv.style.top = indexadvTop + 'px';
// indexadv.style.zIndex = '1';
} else if (window.pageYOffset <= breaking && anchored === true) {
anchored = false;
console.log('up');
indexadv.style.position = '';
indexadv.style.top = '';
// indexadv.style.zIndex = '';
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment