[英]How to exclude a link in a smooth scrolling script? (jQuery)
我在我的网站上使用Bootstrap 3传送带。 我也在使用这个jQuery脚本:
<script>
$(function() {
$('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;
}
}
});
});
</script>
问题在于,滑动轮播时,它会单击#carousel
链接。 这使转盘无法正常工作。
我想知道的是,是否可以从脚本中排除#carousel
? 因此,该脚本不适用于#carousel
,但适用于所有其他链接。
谢谢。
只需将其添加到选择器
$('a[href*=#]:not([href=#]):not([href=#carousel])')
您可以将CSS选择器添加到ignore:在构造函数中,将选择器添加到可滚动锚
var scroll = new SmoothScroll('a[href*="#"]', { // Selectors ignore: '[data-scroll-ignore]' });
<a class="nav-link active" data-toggle="pill" href="#nav-tab-card" data-scroll-ignore>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.