【问题标题】:Fixed header that snaps underneath main fixed header固定在主固定头下方的固定头
【发布时间】:2013-10-03 15:32:01
【问题描述】:

我一直在与该站点上的其他一些开发人员一起解决一个问题,其中包含一个固定的标题问题。

我现在在这里更新了小提琴 http://jsfiddle.net/f95sW/

问题

1) 当向下滚动页面时,黄色块需要捕捉到红色块。

请查看代码和演示,任何帮助将不胜感激。

var offset = $(".sticky-header").offset();
var sticky = document.getElementById("sticky-header")
var additionalPixels = 50;

$(window).scroll(function () {

    if ($('body').scrollTop() > offset.top + additionalPixels) {
        $('.sticky-header').addClass('fixed');
    } else {
        $('.sticky-header').removeClass('fixed');
    }


});

【问题讨论】:

标签: jquery css fixed


【解决方案1】:

两个问题。你没有包含一个固定的类,所以我在这个中添加了:

.fixed{
    position: fixed;
    top:52px;
}

jsFiddle example

但更重要的是,您需要将数学更改为:

if ($('body').scrollTop() > offset.top - additionalPixels) {

【讨论】:

    【解决方案2】:

    看起来你错过了 .fixed 类

    .fixed{
        position: fixed;
        top: 0; left:0;
    }
    

    这是更新后的小提琴http://jsfiddle.net/f95sW/2/

    【讨论】:

      猜你喜欢
      • 2018-06-18
      • 2013-02-11
      • 2016-08-11
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      • 2016-05-06
      • 2017-07-01
      • 2020-08-20
      相关资源
      最近更新 更多