FullPage.js - add active class to menu anchor when on a nonematching section

穿精又带淫゛_ 提交于 2019-12-06 11:10:59

I would make use of the plugin callbacks to achieve that.

You could make use of afterLoad with something like this:

$.fn.fullpage({
    slidesColor: ['red', 'blue'],
    afterLoad: function(anchor, index){
        var activeItem;

        if(index == 1 || index == 2 || index == 3){
            activeItem = $('#menu').find('li').first()
        }else{
             activeItem = $('#menu').find('li').last()    
        }

        activeItem
            .addClass('active')
            .siblings().removeClass('active');
    }
});

Note that I'm not using the menu option anymore to handle the active class as I wish.

Live example

This is old but for anyone else that comes along.. this feature is built in to Fullpage.js. Just change "lockAnchors: false," to "lockAnchors: true," in your fullpage.js defaults, or as an option when you call it up. Then you need to add your css for the #menu li.active that is created. Done.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!