javascript - 当 jQuery 更改框高度时,Bootstrap scrollspy 不起作用

标签 javascript jquery html css twitter-bootstrap

我有一个关于 Bootstrap 的有趣问题。我需要在我的网页上有带有 scrollspy 的全屏框。这是JsFiddle上的演示.

这有效,但是 Bootstrap JavaScript 不会注意到在调整框大小时使 jQuery 发生的变化。 Bootstrap 只能看到 600px 我在 CSS 中给出的起始值。当我滚动时,我的菜单不会准确显示事件值。有什么帮助吗?谢谢!

我的代码:

.content-wrapper{
    display:table;
    width:100%;
    color:black;
    text-align:center;
    margin:0 0 0 0 !important;
    padding:0px !important;
    height:auto;
    min-height:850px;
}
.content-wrapper > .content{
    width:100%;
    display: table-cell;
    vertical-align:middle;
    text-align:center;
    font-size:100%;
    font-weight:bold;
    padding:40px 0 0 0;
    height:auto;
}



<div class="collapse navbar-collapse" id="cf-navigation-top-bar">
        <ul class="nav navbar-nav navbar-right">
                <li><a href="#c1">Content 1</a></li>
                <li><a href="#c2">Content 2</a></li>
                <li><a href="#c3">Content 3</a></li>
        </ul>
</div>

<div class="content-wrapper" id="c1">
    <div class="content">
            Content 1
    </div>
</div>
<div class="content-wrapper" id="c2">
    <div class="content">
            Content 2
    </div>
</div>
<div class="content-wrapper" id="c3">
    <div class="content">
            Content 3
    </div>
</div>

$("body").scrollspy({target: "#cf-navigation-top-bar"});

var BrowserSize=function(a){
    var b=new Array();
    b["height"]=$(window).height();
    b["width"]=$(window).width();
    return b[a];
};
$(document).ready(function(){
    $(".content-wrapper, .content-wrapper > .content").each(function() {
        var boxHeight = $(this).height();
        if(boxHeight > BrowserSize("height"))
        {
            $(this).css("height","auto");
        }
        else
        {
            $(this).css("height",BrowserSize("height")+1);
        }
    });
});
$(window).resize(function(){
    $(".content-wrapper, .content-wrapper > .content").each(function() {
        var boxHeight = $(this).height();
        if(boxHeight > BrowserSize("height"))
        {
            $(this).css("height","auto");
        }
        else
        {
            $(this).css("height",BrowserSize("height")+1);
        }
    });
});

最佳答案

在 scrollspy.js 中,您可以为最大框添加最大高度

  $.fn.scrollspy.Constructor = ScrollSpy

  $.fn.scrollspy.defaults = {
    offset: 10,
    height: 900px //<-change the height here
  }

关于javascript - 当 jQuery 更改框高度时,Bootstrap scrollspy 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26213400/

相关文章:

javascript - 查找列中的最小值

javascript - 基于来自 Dom 元素的 CSS 路径模拟点击

Javascript:获取点击事件的数据属性

html - safari html5 视频加载问题

javascript - Html 表单 - 查看和更改信息

javascript - 如何从 firebase v9 获取服务器时间戳?

javascript - 更改可观察数组时不调用 knockout 订阅

javascript - jquery 在同一函数中将两个 div 交叉淡入淡出在一起

javascript - 使用常量访问 JSON

javascript - 获取反向引用值并修改这些值