引导滚动间谍与平滑滚动错误的目标



我试图使用引导程序使Scrollspy平滑滚动。这是有效的,但滚动目标是错误的。

你可以看到我的小提琴:http://jsfiddle.net/gdfqtLxh/12/

>>此屏幕截图<lt;

更新视频:https://youtu.be/pZCc90Dv5kw

如果您单击第二个菜单,它会很好地工作,但当您单击第三个菜单时,它不会到达正确的目标。

这是我的javascript。。

$("#list-example a[href^='#']").on('click', function(e) {
// prevent default anchor click behavior
event.preventDefault();
// store hash
var hash = this.hash;
// animate
$('.scrollspy-example').animate({
scrollTop: $(hash).offset().top
}, 300);
});

更新视频(添加了一些文本(:https://youtu.be/921oDDaSZq0

您的jsfiddle在Firefox中正常工作,但在Chrome中则不然。

我用bootstrap的原始链接替换了你所有的js和css链接,以防它们过时,现在它可以在Chrome中使用了。

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

点击此处查看此jsfiddle:http://jsfiddle.net/h6nc9ro4/

我还去掉了你的javascript代码,因为它不是必需的。

最新更新