[英]Smooth scrolling Bootstrap 3
我在嘗試使頁面平滑滾動時遇到一些問題,基本上我在這樣的頁面周圍有錨標簽:
<li><a href="#description">Module Description</a></li>
...
<section id=" description ">
而且我正在使用以下運行良好的javascript,但問題是,如果我使用此腳本,則bootstrap 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進行了測試。
$('a[href*=#]:not([href=#])')
非常通用,也會更改目標錨,例如模態。 嘗試使其通用性降低:
<ul id="insidepagenav">
<li><a href="#description">Module Description</a></li>
$('ul#insidepagenav > li > a[href*=#]:not([href=#])')
如果您更換
a[href*=#]:not([href=#])
同
a[href*=#]:not([href=#]):not([href=#idname])
您可以防止平滑滾動對該特定鏈接起作用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.