我已经得到了这段代码,它遍历了我所有的内部href
,但我看不出能够弄清楚如何为链接到的链接之一创建异常div #section1
.我需要某种围绕 section.addClass("active");
行的 if
语句,但我不知道使用哪些条件来实现此目的。你能帮忙吗?
if (scrolledTo > target - threshold && scrolledTo < target + threshold) {
//remove all selected elements
sections.removeClass("active");
//add current selected element.
section.addClass("active");
}
最佳答案
像这样:
$('a[href^="#"]:not(#exception)').click(function (event) {
//do stuff
});
fiddle :http://jsfiddle.net/KyleMuir/vD3vP/1/
编辑:您可以像这样确定是否是异常:
//Smooth scroll when user click link that starts with #
$('a[href^="#"]').click(function (event) {
if (!$(this).is('#exception')) {
alert('Hi');
}
//prevent the browser from jumping down to section.
event.preventDefault();
});
关于javascript - 如何在 jQuery 中为 "active"滚动菜单的链接创建异常(exception)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20035216/