2013-10-09 55 views
0

我有一些問題想有一個平滑滾動在我的網頁,基本上我有錨標籤頁左右這樣的:平滑滾動引導3

<li><a href="#description">Module Description</a></li> 
... 
<section id=" description "> 

,我使用下面的JavaScript工作正常,但問題是,如果我使用這個腳本,模式和自舉3擊穿的其他功能和了,我想這可能是這個腳本的解決方案或不能正常工作

$('a[href*=#]:not([href=#])').click(function() { 
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
    || location.hostname == this.hostname) { 

    var target = $(this.hash); 
    target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); 
    if (target.length) { 
    $('html,body').animate({ 
     scrollTop: target.offset().top 
    }, 1000); 
    return false; 
    } 
} 
}); 

有其他類似腳本與bootstrap 3 謝謝

回答

3

$('a[href*=#]:not([href=#])')將是非常通用的也將改變目標定位例如模態。儘量做到少通用:

<ul id="insidepagenav"> 
<li><a href="#description">Module Description</a></li> 

$('ul#insidepagenav > li > a[href*=#]:not([href=#])')

+0

太棒了!非常感謝,解決了這個問題,很樂意給你一個積極的點,但沒有足夠的聲譽。 – Manza

0

如果更換

a[href*=#]:not([href=#]) 

a[href*=#]:not([href=#]):not([href=#idname]) 

可以防止平滑滾動從一個具體環節的工作