Adding or removing sections/slides to fullPage.js after initialization

前端 未结 4 1503
灰色年华
灰色年华 2020-12-06 03:16

I have a tree-structured database and in my website I am going down the tree as I show their content in \"sections\" and \"slides\" of fullPage.js plugin. The problem is, wh

4条回答
  •  失恋的感觉
    2020-12-06 03:38

    As said in the link you post, fullpage.js doesn't provide a direct way of doing it. The only way is destroying and initializing fullpage.js each time you add a new section or slide. To avoid blinkings, we can remember the active section and slide to initialize again with those values.

    Reproduction online

    init();
    
    function init(){
        $('#fullpage').fullpage({
            sectionsColor: ['yellow', 'orange', '#C0C0C0', '#ADD8E6'],
        });
    }
    
    //adding a section dynamically
    $('button').click(function(){
        $('#fullpage').append('
    New section
    '); //remembering the active section / slide var activeSectionIndex = $('.fp-section.active').index(); var activeSlideIndex = $('.fp-section.active').find('.slide.active').index(); $.fn.fullpage.destroy('all'); //setting the active section as before $('.section').eq(activeSectionIndex).addClass('active'); //were we in a slide? Adding the active state again if(activeSlideIndex > -1){ $('.section.active').find('.slide').eq(activeSlideIndex).addClass('active'); } init(); });

提交回复
热议问题