How to properly detect when a static element overlaps a fixed element y position on event scroll ?
I'm sure I've done this before, but at the moment I missing something (example here http://jsbin.com/hetovoduwi/edit?css,js,console,output).
js:
window.addEventListener('scroll', function () {
console.log('win y:' + window.scrollY);
var b = document.querySelector('.b').getBoundingClientRect();
console.log(b);
/*
console.log('(b.top+b.height)', (b.top+b.height));
console.log('window.scrollY - 50', window.scrollY - 50)
*/
});
html:
<div class="a"></div>
<div class="b"></div>
css:
.a {
position: fixed;
width: 50px;
height: 50px;
background: red;
top: 50px;
}
.b {
margin-top: 30vh;
width: 50px;
height: 50px;
background: blue;
}
body {
height: 100vh;
}