Created
October 4, 2016 10:36
-
-
Save yaroslavKas/f6daddaea420d6194d63aeec4bde61c1 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
document.addEventListener("DOMContentLoaded", function() { | |
function scrollWidget(){ | |
var widget = document.getElementById('villa-calendar-wrapper'), | |
headerHeight = document.getElementById('header-outer').offsetHeight, | |
widgetPositionParams = widget.getBoundingClientRect(), | |
scrollHeight = window.pageYOffset || document.documentElement.scrollTop; | |
if(widgetPositionParams.top < scrollHeight){ | |
widget.style.top = headerHeight + 20 + 'px'; | |
widget.classList.add('fixed'); | |
} | |
else{ | |
widget.classList.remove('fixed'); | |
} | |
} | |
scrollWidget(); | |
window.onscroll = function(){ | |
scrollWidget(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment