2012-04-25 42 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