Created
February 7, 2017 08:34
-
-
Save nicco88/e127ce43b45fc192109d97106493e921 to your computer and use it in GitHub Desktop.
This file contains 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 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