2012-04-25 70 views
0

我正在使用引导程序,并且我有一个带有引导程序的scrollspy页面。我无法将Scrollspy添加到其他页面,因为我的链接意外启动。是否有可能使用简单的jQuery函数来添加:更改页面加载引导程序2.0的主体标记

data-spy="scroll"data-target=".subnav"到页面正文的特定页面加载。

将滚动间谍添加到a div="span12"似乎不起作用,但是,放置在主体上的功能确实可行。

如果其他人有一个简单的解决方案来使用这个或另一种方法,请让我知道。

这里是目前我的代码:

<body> <!-- Add it here to make it work --> 
<div class="span12" style="background: #fff;"> <!-- OR add it here and see if it works, if so then I can avoid the function all together. --> 
    <div class="span11"> 
    <header> 
    <h1>TITLE</h1> 
    <h3>The full history of..<small>By Jane Doe</small></h3> 
    <div class="subnav"> 
     <ul class="nav nav-pills"> 
     <li class="active"><a href="#overview">Introduction</a></li> 
     ... 
     </ul> 
    </div> 
    </header> 

    <section id="overview"></section> 
    <section id.... 
</div> 
</div> 

而且我使用修复topnav脚本:

$(document).scroll(function(){ 
    // If has not activated (has no attribute "data-top" 
if (!$('.subnav').attr('data-top')) { 
    // If already fixed, then do nothing 
    if ($('.subnav').hasClass('subnav-fixed')) return; 
    // Remember top position 
    var offset = $('.subnav').offset() 
    $('.subnav').attr('data-top', offset.top); 
} 

if ($('.subnav').attr('data-top') - $('.subnav').outerHeight() <= $(this).scrollTop()) 
    $('.subnav').addClass('subnav-fixed'); 
else 
    $('.subnav').removeClass('subnav-fixed'); 
}); 

$('#navbar').scrollspy();

回答

2

尝试

$(document).load(function() { 
    $('body').attr('data-spy', 'scroll').attr('data-target', '.subnav'); 
}); 
+0

而且,引导文档页面有数据目标subnav。我是否需要指定才能工作? – 2012-04-25 20:44:34