Fixed div to fade in and out when footer appears

Fixed div to fade in and out when footer appears

I have a query where i have a fixed div with contact details that i would like to be on show until the footer is in view then it will fadeout. When the footer is out of view when the user scrolls up, the fixed div then fadesIn. I have had a look at some examples and using my own div tags and styling and nothing happens. An example i have used is:

  
  1. $('#footer').appear();
  2. $('#footer').on('appear', function(){
  3. $('#fixed_div').fadeOut();
  4. });

  5. $('#footer').on('disappear', function(){
  6. $('#fixed_div').fadeIn();
  7. });
  8. HTML-BASIC
  9. <div id="footer">
  10. <div class="footer-wrapper">
  11. Footer details here
  12. </div>
  13. </div>

  14. <div id="fixed_div">
  15. <ul>
  16. <li><h1>details here</h1></li>
  17. <li><h1>details here</h2></li>
  18. </ul>
  19. </div>

I have also used an example from stackoverflow which works but not in firefox and fades in and out at a random point in my site (seems to be the last blog of my site -wordpress):


  
  1. var secondval = $('#footer').offset().top;
  2. $(window).scroll(function(){
  3. var firstval = $(document).scrollTop();

  4. if(firstval >= secondval)
  5. {
  6. $('#fixed_div').fadeOut();
  7. }else{
  8.       $('#fixed_div').fadeIn();

  9. });

Anyone have any suggestions to where the problem may be on either of these examples? Thanks in advance!