Initializing fullpage.js multiple times in an angular app

穿精又带淫゛_ 提交于 2019-12-05 08:41:20

Update:

Now you can make use of the official Angular component for fullPage.js.


Just destroy it whenever and wherever you initialize it. Just before the initialization, for example:

//destroying
if (typeof $.fn.fullpage.destroy == 'function') { 
    $.fn.fullpage.destroy('all');
}

//initializing 
$('#fullpage').fullpage();

Or you can just check if it was initialized before checking the class/flag that fullPage.js adds to your html element (supposing this doesn't get modified in your ajax calls).

//destroying
if($('html').hasClass('fp-enabled')){
    $.fn.fullpage.destroy('all');
}

//initializing 
 $('#fullpage').fullpage();

For using the router:

If you're using the router in Angular 4, you can simply edit the mnFullpage.directive.js in the ngx-fullpage component directive. Add a boolean for "initialized" at the top and then do a simple if statement. If fullpage is initialized then destroy('all'). This way, when you use the router to go from page to page they will still retain the fullpage.js functionality.

  1. Go to ngx-fullpage\components\fullpage\mnFullpage.directive.js
  2. Scroll down to the ngOnInit function
  3. Add this variable to the top of the page (under var DIRECTIVE_NAME)

    var initialized = false;

  4. replace the bottom initializer with this:

    /**
     * Enable fullpage for the element
     */
    if(initialized)
    {
      $.fn.fullpage.destroy('all');
    }
    $(this._el.nativeElement).fullpage(this.options);
    initialized   = true;
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!