我爲我的網站使用twitter引導。導航欄鏈接在點擊時激活,但當我滾動到頁面的特定部分時,我想要相同的效果。即(鏈接變成灰色的點擊,我想同樣的效果,當我在滾動的那款)Twitter Bootstrap 3導航菜單意外的行爲
// jQuery代碼
$(document).ready(function() {
$(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 - 50
}, 1000);
return false;
}
}
});
});
$('.nav li a').on('click', function() {
$(this).parent().parent().find('.active').removeClass('active');
$(this).parent().addClass('active');
});
});
我一直在使用Twitter的scrollspy嘗試,但因爲這行代碼的scrollTop:target.offset()。top - 50我有一些問題。示例當我點擊聯繫人時,它會繼續聯繫部分,但導航菜單中的投資組合鏈接處於活動狀態。
我的網站: www.nakibmomin.com
這工作完美的滾動,但當我點擊例如關於我的家庭鏈接眨眼.....如果我點擊關於我的技能眨眼 – Nakib 2014-09-08 22:59:36
與is(':animated'),你可以檢查是否其他動畫是進行中。我修改了腳本。 – user2721793 2014-09-09 07:09:03
完美....感謝的人 – Nakib 2014-09-09 19:25:16