Menu scrolling

Post Reply
asyst
Posts: 3
Joined: 08 Feb 2018, 11:21

18 Jun 2019, 10:32

How to keep menu scroll position after changing page when we have several menu items

aragorn
Posts: 3706
Joined: 29 Jun 2013, 12:38

21 Jun 2019, 11:45

Please add the following js codes to layout.js;

Code: Select all

    /** 
 * PrimeFaces Apollo Layout
 */
PrimeFaces.widget.Apollo = PrimeFaces.widget.BaseWidget.extend({
    
    init: function(cfg) {
        ...
        this.nano = this.menuContainer.find('.nano');

        this._bindEvents();
 /*** Refactor the following lines ********/
        var nanoOptions = {flash:true};
        
        if(!this.isHorizontal() && !this.isSlim()) {
            this.restoreMenuState();
            this.bindMenuScroll();
            
            var scrollTop = $.cookie('apollo_menu_scrollPosTop');
            if (scrollTop != null) {
                nanoOptions['scrollTop'] = scrollTop;
            }
        }
        
        this.nano.nanoScroller(nanoOptions);
/********************end*************************/

        this.nano.children('.nano-content').removeAttr('tabindex');
    },
    
/** Add the following methods ****************/
    bindMenuScroll: function() {
        var $this = this;
        this.nano.on('update', function(e, values){
            $this.saveScrollPosition(values.position);
        });
    },
    
    saveScrollPosition: function(position) {
        $.cookie('apollo_menu_scrollPosTop', position, {path: '/'});
    },
    
    clearScrollPosition: function() {
        $.removeCookie('apollo_menu_scrollPosTop', {path: '/'});
    },
/*********************end***************************/

    _bindEvents: function() {
    ...
    }
    ...
}
...
Best Regards,

Post Reply

Return to “Apollo - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests