我正在使用BootStrap 3構建單頁網站。要移動到頁面的不同部分,我在http://css-tricks.com/snippets/jquery/smooth-scrolling/處找到了平滑滾動功能,它工作正常。Bootstrap 3和ScrollTop功能:#鏈接衝突
$(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;
}
}
});
});
平滑滾動檢測環節,從第 <a href="#zone">Scroll to Section Zone</a>
但鏈接以#開始在引導旋轉木馬也使用data-target="#myCarousel"
所以按鈕移動到上一張/下一張幻燈片在幻燈片的行爲模式奇怪的方式。
我已經接近沒有Javascript的知識,但我意識到代碼的第二行是關於要避免的鏈接:所以我把「#myCarousel」放在該部分。 下面你可以找到編輯的第二行:(!非常令人驚訝)
$('a[href*=#]:not([href=#],"#myCarousel")').click(function() {
我的解決方案的工作......幾乎工程!
只有一個問題:滾動不再平滑。
點擊按鈕,在目標鏈接上跳轉頁面。
任何想法爲什麼不光滑?
發現的解決方案
感謝所有的答案。
之前發佈這個要求,我做了我的搜索jquery api
我找到一個解決方案:現在二線讀$('a[href*=#]').not("[href=#], [href=#myCarousel]").click(function() {
謝謝您的回答和「破壞」 javascritp對不起! :-) –
對不起。您的解決方案不起作用。 –