[英]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.