I have a fixed footer that expands when the scroll event is triggered and shrink after 1500ms of the last scroll or move.
Below is a simplified version of the production script where I'm using lodash throttle and remove event listener when destroying the components.
var
el = document.getElementsByTagName('div')[0],
timer
;
function rest(){
clearTimeout(timer);
timer = setTimeout(() => {
el.classList.add("rest");
}, 1500);
el.classList.remove("rest");
}
window.addEventListener('scroll', rest);
i {
display:block;
height: 100px;
background: gray;
margin: 50px 20px;
list-style:none;
}
div {
position: fixed;
bottom: 0;
height: 50px;
width: 100%;
background: blue;
transition: all 0.6s;
}
.rest {
height: 20px;
background: red;
}
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
<div class="rest"></div>
I just started using the intersection observer and I'm wondering how I can achieve the same behavior, since it's a fixed element there is no intersection, the only way I can think of, is creating a "sentinel" element and change its position on every intersection, which seems to be an overkill and defy the main purpose of including the intersection observer "Performance"
So with no clear idea, I'm turning to you guys and your expertise.