這裏的jsfiddle鏈接: http://jsfiddle.net/asif097/HHEqx/手動滾動添加類不在這裏工作了
您好,
在你上面的鏈接會發現當一個鏈接被點擊一類active
是越來越添加上
('.nav-inner a')
,同時頁面也滾動。 (詳細瞭解代碼):
$(document).ready(function() {
$('html, body').animate({
scrollTop: $(".target1").offset().top
}, 1000);
$('#link1').click(function() {
$('html, body').animate({
scrollTop: $(".target1").offset().top
}, 1000);
$('.nav-inner a').removeClass("active");
$(this).addClass("active");
});
$('#link2').click(function() {
$('html, body').animate({
scrollTop: $(".target2").offset().top,
}, 1000);
$('.nav-inner a').removeClass("active");
$(this).addClass("active");
});
$('#link3').click(function() {
$('html, body').animate({
scrollTop: $(".target3").offset().top
}, 1000);
$('.nav-inner a').removeClass("active");
$(this).addClass("active");
});
});
現在我希望這樣的事情發生,當我手動滾動addClass()運行相同的方式。試過這一個:
$('html, body').scroll(function()
{
if(($('html, body').scrollTop())<1000)
{
$(".nav-inner a").removeClass('active');
$(".nav-inner a:nth-child(1)").addClass('active');
}
else if(($('html, body').scrollTop())<2000)
{
$(".nav-inner a").removeClass('active');
$(".nav-inner a:nth-child(2)").addClass('active');
}
else
{
$(".nav-inner a").removeClass('active');
$(".nav-inner a:nth-child(3)").addClass('active');
}
});
但,不能正常工作。任何人可以修復我的代碼? (說明是預料)
謝謝。
感謝這一個工程。喜歡滾動計數部分。 – Asif 2013-02-16 09:59:53
@如果不客氣 – 2013-02-16 11:59:32