-
-
Save alpenzoo/a89a43c789dcb5a21a87cf8d8cdcc2cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
if (window.innerWidth > 640) { | |
var floatParentNode = document.querySelector('.js-parent'); | |
var floatNode = document.querySelector('.js-float'); | |
var valScrollForFixed = floatParentNode.getBoundingClientRect().top + window.pageYOffset - document.querySelector('.js-header').offsetHeight; | |
window.addEventListener('scroll', function () { | |
if (window.innerHeight > floatNode.offsetHeight) { | |
var windowScrollTop = window.pageYOffset; | |
var footerTop = document.querySelector('.js-footer').getBoundingClientRect().top + windowScrollTop; | |
var footerHeight = document.querySelector('.js-footer').clientHeight; | |
var valScrollForAbs = windowScrollTop + floatNode.offsetHeight + document.querySelector('.js-header').offsetHeight + 20; | |
if (valScrollForAbs >= footerTop) { | |
// floatNode.classList.remove('fixed'); | |
floatNode.classList.add('fixed-footer'); | |
floatNode.style.bottom = -(document.body.clientHeight - windowScrollTop - window.innerHeight - footerHeight - 20) + 'px'; | |
} else { | |
floatNode.classList.remove('fixed-footer'); | |
floatNode.style.bottom = ''; | |
if (windowScrollTop >= valScrollForFixed) { | |
floatNode.classList.add('fixed'); | |
} else { | |
floatNode.classList.remove('fixed'); | |
} | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment