2016-10-24 6 views
0

スクロール要素がサイトのフッターに重ならないようにしようとしています。私はそれが特定の要素のページの上部に重ならないところにそれを持ってきましたが、それでもフッタに重なっています。ここでフッタにオーバーラップする固定要素

は、私は現在の場所に持っているコードです:

// fix the orange box to the top after scrolling a certain amount 
$(window).scroll(function() { 
    // get the scroll position top 
    var window_pos = $(window).scrollTop(); 

    // fix the element on scroll 
    if (window_pos >= $('#sticky').offset().top) { 
     $('#suggestions').attr('style', 'position: fixed; top: 0px;'); 


     // prevent overlapping into the footer 
     if (window_pos >= $('#sticky2').offset().top || window_pos >= $('.footer').offset().top) { 
      alert("exceeded"); 
      $('#suggestions').attr('style', 'position: absolute'); 
     } else { 
      // restore fixed position 
      if ($(document).scrollTop() + window.innerHeight < $('#sticky2').offset().top) { 
       $('#suggestions').attr('style', 'position: fixed; top: 0px;'); 
      } 
     } 
    } else if (window_pos < $('#sticky').offset().top - 20) { 
     $('#suggestions').attr('style', 'position: absolute'); 
    } 
}); 

と、次のように2つのdiv要素は以下のとおりです。

<div id="sticky" style="height: 20px; margin-top: 5px; visibility: hidden;"></div> 
<div id="sticky2" style="height: 50px; margin-top: 10px; visibility: hidden;"></div> 

任意の助けをいただければ幸いです。

ありがとうございます!

答えて

0

は、私はそれを試してみましたが、悲しいことに、それは動作しませんでした。この

$(window).scroll(function() { 
    // get the scroll position top 
    var window_pos = $(window).scrollTop(); 

    // fix the element on scroll 
    if (window_pos >= $('#sticky').offset().top) { 
     $('#suggestions').css({ 
      'position': 'fixed', 
      'top': '0px' 
     }); 


     // prevent overlapping into the footer 
     if (window_pos >= $('#sticky2').offset().top || window_pos >= $('.footer').offset().top) { 

      $('#suggestions').css({ 
       'position': 'static', 
       'top': 'auto' 
      }); 
     } else { 
      // restore fixed position 
      if ($(document).scrollTop() + window.innerHeight < $('#sticky2').offset().top) { 
       $('#suggestions').css({ 
        'position': 'fixed', 
        'top': '0px' 
       }); 
      } 
     } 
    } else if (window_pos < $('#sticky').offset().top - 20) { 
     $('#suggestions').css({ 
      'position': 'static', 
      'top': 'auto' 
     }); 
    } 
}); 
+0

を試してみてください。それが役立つなら、私が経験しているもののスクリーンショットです。 http://imgur.com/a/TeyfA – user2101411

+0

すべてのhtml cssとjsをjs fiddleまたはcodepenに投稿すると、実際のコードを理解しやすく変更することができます –

+0

私はそれがビジネスに敏感であることを望みます。 Firefoxでは、フッタがChromeでよりも多く重なっているということです。 – user2101411

関連する問題