-1

There is a fixed Div at the bottom, I want to hide that fixed div when a footer div start showing in the screen when I scroll the page down and also show the fixed div back when I Scroll up.

.content{
height:600px;
font-size:30px;
display:flex;
align-items:center;
justify-content:center;}

.fixedDiv{
   padding: 10px;
    background-color: yellow;
    position: fixed;
    bottom: 5%;
    left: 50%;
    transform: translate(-50%, 0);
    z-index: 10;
}

.footerDiv{
background:red;
height:300px;
width:100%;
font-size:30px;
display:flex;
align-items:center;
justify-content:center;
}
<div class="content">CONTENT
</div>
<div class="fixedDiv">Hide Me When Footer Comes</div>
<div class="footerDiv">FOOTER</div>
Arjun Pandi
  • 176
  • 11

1 Answers1

1

After improvising this little How to Check if element is visible after scrolling?

$(window).scroll(function() {    
   if (isScrolledIntoView('.footerDiv') )
     $('.fixedDiv').css('visibility','hidden');      
   else{
     $('.fixedDiv').css('visibility','visible');
  }
});


function isScrolledIntoView(elem) {
  var docViewTop = $(window).scrollTop();    
  var docViewBottom = docViewTop + $(window).height();

  var elemTop = $(elem).offset().top;    
  var elemBottom = elemTop + $(elem).height();   

  return ((elemTop < docViewBottom));
 }

https://jsfiddle.net/t0uogj3v/

Murali Nepalli
  • 1,458
  • 4
  • 16