简体   繁体   English

使用fullPage.js将活动类添加到两个/拆分菜单

[英]Adding active class to two / split menu with fullPage.js

I'm using fullPage.JS and have the section Menu working fine (scrolls up and down) apart from I want half my menu in the header and half in the footer. 我正在使用fullPage.JS,并且让菜单部分工作正常(上下滚动),除了我希望菜单的一半放在页眉中,一半放在页脚中。 This works fine for navigation but is not adding the class "active" to the li in the footer only to the header. 这对于导航工作正常,但是不会将“活动”类仅添加到页眉中的页脚中的li。 I'm assuming its because both menu's have the same ID as removing the header menu id makes the footer menu work with the active class. 我假设它是因为两个菜单都具有与删除标题菜单ID相同的ID,从而使页脚菜单可与活动类一起使用。 How do I get both to work? 我如何同时工作? callbacks perhaps? 回调也许?

Similar to this answer: FullPage.js - add active class to menu anchor when on a nonematching section 类似于此答案: FullPage.js-在不匹配的部分上将活动类添加到菜单锚点

$('#fullpage').fullpage({
    anchors: ['PAGE1','PAGE2','PAGE3','PAGE4','PAGE5','PAGE6',],
    menu:'#menu',
});
<div id="headermenu">
    <ul id="menu">
        <li data-menuanchor="PAGE1"><a href="#PAGE1">PAGE1</a></li>
        <li data-menuanchor="PAGE2"><a href="#PAGE2">PAGE2</a></li>
        <li data-menuanchor="PAGE3"><a href="#PAGE3">PAGE3</a></li>
    </ul>
</div>

<div id="footermenu">
    <ul id="menu">
        <li data-menuanchor="PAGE4"><a href="#PAGE4">PAGE4</a></li>
        <li data-menuanchor="PAGE5"><a href="#PAGE5">PAGE5</a></li>
        <li data-menuanchor="PAGE6"><a href="#PAGE6">PAGE6</a></li>
    </ul>
</div>

In HTML the id attribute must be unique. 在HTML中, id属性必须唯一。 If you want a selector to apply to more than one element use CSS classes, eg: 如果要将选择器应用于多个元素,请使用CSS类,例如:

<ul class="my-menu">
</ul>

...
<ul class="my-menu">
</ul>

Then your selector would look like: 然后您的选择器将如下所示:

menu:'.my-menu'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM