I'm struggling to find out how to detect when a div with position fixed start and finish to hover a certain div while scrolling.
I've a div always in position fixed and centered in my window. While I'm scrolling my page, I would like that the fixed div when starts to hover another one changes its color and remove the color once it finishes to hover. I attached a little schema to illustrate my problem. To resume:
The fixed div when page loads has black color -> Starts to hover a second div, the color turns to white -> Finish to hover the second div, the color is back to black.
I found this issue: Detect when a position: fixed; element crosses over another element
It works when the div start to cross the second one, but it doesn't reset the color when the hover is finished. My code:
$(window).scroll(function() {
if ($('div.fixed').offset().top < ($(".div-to-cross").offset().top - 0)) {
$('div.fixed').removeClass('white');
} else {
$('div.fixed').addClass('white');
}
});
Thanks in advance for your help.