为什么Bootstrap的卷轴不起作用?

4 javascript twitter-bootstrap

我有一个简单的Bootstrap模态设置,在模态中我有一个内容与nav和scrolllspy设置.但是,它不起作用.我看到它被激活,但导航永远不会更新.

完整的源代码太长了,你无法看到我得到的效果,所以我设置了一个jsfiddle

我正在使用该data-spy="scroll"方法来启用它.我做错了什么?为什么导航器不会根据您的位置进行更新?

小智 7

bootstrap scrollspy仍然有一些错误(我真的很喜欢bootsrap).我使用自定义脚本,它的工作方式更好,更灵活:

<script type="text/javascript">
$(document).ready(function(){
var lastId, topMenu = $(".menu-sidebar"),
    topMenuHeight = topMenu.outerHeight() + 150,
    menuItems = topMenu.find("a"),
    scrollItems = menuItems.map(function() {
        var item = $($(this).attr("href"));
        if (item.length) {
            return item;
        }
    });

menuItems.click(function(e) {
    var href = $(this).attr("href"),
    topMenuHeight = topMenu.outerHeight() + 20,
        offsetTop = href === "#" ? 0 : $(href).offset().top - topMenuHeight + 1;
    $('html, body').stop().animate({
        scrollTop: offsetTop
    }, 300);
    e.preventDefault();
});

$(window).scroll(function() {
    var fromTop = $(this).scrollTop() + topMenuHeight;

    var cur = scrollItems.map(function() {
        if ($(this).offset().top < fromTop) return this;
    });
    cur = cur[cur.length - 1];
    var id = cur && cur.length ? cur[0].id : "";

    if (lastId !== id) {
        lastId = id;
        menuItems.parent().removeClass("active").end().filter("[href=#" + id + "]").parent().addClass("active");
    }
});
});
</script>
Run Code Online (Sandbox Code Playgroud)

来源:http://jsfiddle.net/mekwall/up4nu/