我在尝试在页面中平滑滚动时遇到一些问题,基本上我在页面周围有 anchor 标记,如下所示:
<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=#])')
将非常通用,也会更改模态的目标 anchor 。尝试让它不那么通用:
<ul id="insidepagenav">
<li><a href="#description">Module Description</a></li>
$('ul#insidepagenav > li > a[href*=#]:not([href=#])')
关于javascript - 平滑滚动 Bootstrap 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19263600/