Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何为“我的”链接创建异常;主动的;jQuery中的滚动菜单?_Javascript_Jquery_Html_Menu_Href - Fatal编程技术网

Javascript 如何为“我的”链接创建异常;主动的;jQuery中的滚动菜单?

Javascript 如何为“我的”链接创建异常;主动的;jQuery中的滚动菜单?,javascript,jquery,html,menu,href,Javascript,Jquery,Html,Menu,Href,我的所有内部href中都有这段代码,但我看不出如何为链接到div#section1的链接之一创建异常。我需要围绕节的if语句行,但我不知道使用哪些条件来实现这一点。你能帮忙吗 代码: if(滚动到>目标-阈值和滚动到

我的所有内部
href
中都有这段代码,但我看不出如何为链接到div
#section1
的链接之一创建异常。我需要围绕
节的
if
语句行,但我不知道使用哪些条件来实现这一点。你能帮忙吗

代码:

if(滚动到>目标-阈值和滚动到<目标+阈值){
//删除所有选定元素
章节。removeClass(“活动”);
//添加当前选定的元素。
第3.2节:添加类(“活动”);
}
像这样:

$('a[href^="#"]:not(#exception)').click(function (event) {
    //do stuff
});
小提琴:

编辑:您可以确定它是否是这样的异常:

//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();

});

提琴:除非我误解了你的问题,否则你可以加上

$('a[href^="#section1"]').removeClass("active");
在第.addClass节之后(“活动”);在for循环的checkSectionSelected()中

如果不使用以下方法不必要地更新DOM树,则可以做得更好:

section.not('[href^="#section1"]').addClass("active");
在此处测试:


Andrei

你的小提琴只是JS,没有HTML来演示这个问题。谢谢,但是如果我添加了这样一个异常,那么当我滚动到section2 div上时,section1 div不会删除类(“活动”),因为section1 div从未添加到sections中!我需要某种if语句,这样它就跳过了section1div上的addClass(““active”)!让它使用:if(!section.is('#nav_section1'){section.addClass(“active”)}
section.not('[href^="#section1"]').addClass("active");