【问题标题】:stop fixed element from scrolling into the footer when the browser window is a smaller height当浏览器窗口的高度较小时,阻止固定元素滚动到页脚
【发布时间】:2015-10-23 15:25:30
【问题描述】:

我已经尝试了下面的 jQuery / 逻辑,但它不起作用......问题是我有一个固定的导航,这很好。但是当用户在较小的高度分辨率/屏幕上时,即。笔记本电脑的固定滚动导航,当滚动到页面底部时 - 与页脚元素重叠。这看起来真的很糟糕。

以下内容不起作用..似乎只是在页面加载时立即将我的固定元素恢复为绝对位置。

 $(document).ready(function() {
    function checkOffset() {
     if($('.navSmall').offset().top + $('.navSmall').height() 
                                       >= $('#footer-wrapper-4o').offset().top - 10)
    $('.navSmall').css('position', 'absolute');
     if($(document).scrollTop() + window.innerHeight < $('#footer-wrapper-4o').offset().top)
    $('.navSmall').css('position', 'fixed'); // restore when you scroll up
    $('.navSmall').text($(document).scrollTop() + window.innerHeight);
  }
  $(document).scroll(function() {
      checkOffset();
  });
  });

P.S. 有没有一种方法可以通过简单地使用 div &lt;div class="stop"&gt;&lt;/div&gt; 来合并停止点,一旦固定/滚动元素命中,它就无法继续超过该点? p>

【问题讨论】:

  • 你能上传一张它长什么样的照片或一个我们可以修补的 jsfiddle 吗?

标签: javascript jquery css


【解决方案1】:
function checkOffset() {....}

$(window).load(function() {
    $(window).scroll(function() {
      checkOffset();
  });
}

这样使用函数比较好。

【讨论】:

    猜你喜欢
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    相关资源
    最近更新 更多