简体   繁体   English

我想用反应在 fullpage.js 中添加 class 'active',但我不知道如何

[英]I want to add the class 'active' in fullpage.js with react, and I don't know how

I am using fullpage.js and I want that depending on the section in which I am.我正在使用 fullpage.js,我希望这取决于我所在的部分。 Add a class = 'active' or remove that same class.添加 class = 'active' 或删除相同的 class。 For example: if I am in # section1 add 'active' if I leave that and go to # section2 add 'active' in # section2 and delete the 'active' in # section1例如:如果我在 #section1 添加 'active' 如果我离开它和 go 到 #section2 添加 'active' 在 #section2 并删除 'active' 在 #section1

export default class SearchNav extends React.Component {

render(){
    return (
        <div id='fp-nav' class='left'>
            <ul>
                <li>
                    <a href="#section1"></a>
                </li>
                <li>
                    <a href="#section2"></a>
                </li>
                <li>
                    <a href='#section3'></a>
                </li>
                <li>
                    <a href='#section4'></a>
                </li>
            </ul>
        </div>
    )
}

} }


You could create a state with an object which contains boolean props. 您可以使用包含 boolean 道具的 object 创建 state。 Then set an `active` class on each section if the object linked to them gets a `true` value. 如果链接到它们的 object 获得“真”值,则在每个部分上设置一个“活动” class。

And setup a function will trigger false / true to the good prop's object when you click on a section?当你点击一个部分时,设置一个 function 会触发好道具的 object 的false / true吗?

You don't actually need to.你实际上不需要。

fullPage.js automatically adds the active class for you in the active section/slide in addition of adding another "state" class on the body element, (for example fp-viewing-page2-1 ) fullPage.js 除了在body元素上添加另一个“状态” class 之外,还会在活动部分/幻灯片中自动为您添加active class (例如fp-viewing-page2-1

You can read more about these state classes on the documentation.您可以在文档中阅读有关这些 state 类的更多信息。 https://github.com/alvarotrigo/fullPage.js#state-classes-added-by-fullpagejs https://github.com/alvarotrigo/fullPage.js#state-classes-added-by-fullpagejs

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

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