Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'afterLoad' is not triggered when opening the page with anchor #251

Closed
andreyshipilov opened this issue Feb 17, 2014 · 13 comments
Closed

'afterLoad' is not triggered when opening the page with anchor #251

andreyshipilov opened this issue Feb 17, 2014 · 13 comments

Comments

@andreyshipilov
Copy link

In my code I change the 'menu' class after the section load, like this:

        afterLoad: function (anchorLink, index) {
            if (index === 1 || index === 3 || index === 5) {
                menu.addClass('bright').removeClass('dark');
            } else {
                menu.addClass('dark').removeClass('bright');
            }
        }

But, when I first visit the page using anchor (e.g.: /#contact), the menu class is not changed, because 'afterLoad' is not triggered at this point.

Am I doing it wrong or is it a bug?

@alvarotrigo
Copy link
Owner

Which index is your #contact section?
Are you using animateAnchor: false? Coud you add your initialization here?

@andreyshipilov
Copy link
Author

Yeah, I was just editing the issue. I am using animateAnchor: false.

Contact — 4th section.

@alvarotrigo
Copy link
Owner

Solved. Thanks for reporting it.
Let me know if it works well for you now.

@andreyshipilov
Copy link
Author

Tested on 1.7.4 just now. Nope :(

@alvarotrigo
Copy link
Owner

Are you sure the js is not being cached? It works for me.
Can you show me your URL or code?

@alvarotrigo
Copy link
Owner

By the way, if #contact is your 4th section you should use index==4 or rather use the anchorLink to avoid mistakes.
Remember the index starts at 1.

@andreyshipilov
Copy link
Author

No cache (expires: -1 / nginx).
The class for menu is not added.

$(function () {
    'use strict';

    var menu = $('#menu');

    $.fn.fullpage({
        anchors: ['hello', 'about', 'work', 'contact', 'goodbye'],
        menu: '#menu',
        verticalCentered: false,
        easing: false,
        resize: false,
        css3: true,
        animateAnchor: false,
        slidesNavigation: true,
        afterLoad: function (anchorLink, index) {
            switch (index) {
            case 1:
            case 3:
            case 5:
                menu.addClass('bright').removeClass('dark');
                break;
            case 2:
            case 4:
                menu.addClass('dark').removeClass('bright');
                break;
            }
        }
    });
});

@alvarotrigo
Copy link
Owner

Sorry but I can not reproduce your problem. I have used your initialization and the class dark is being added correctly in all cases (scrolling, accessing through the menu or accessing directly by URL with anchor)

You might be doing something wrong somewhere else.
Don't you get any console error messages?

@andreyshipilov
Copy link
Author

Terribly sorry, my bad. The class is applied so the 'afterLoad' is called.
The menu item is not selected as 'active'. So when I go first time anywhere except '#hello' like '#contact', '#work' — the first element in the menu is set to active, not the one related to hash link.
Does it make sense? :)

@alvarotrigo
Copy link
Owner

You are probably forgetting something. Read the documentation about how to use the menu and the use of data-menuanchor.

That's not a bug with the plugin.

@andreyshipilov
Copy link
Author

I am using it like this.

        <ul id="menu" class="bright">
            <li data-menuanchor="hello" class="active">
                <a href="#hello" class="icon-hello">
                    <span>Hello</span>
                </a>
            </li>
            <li data-menuanchor="about">
                <a href="#about" class="icon-about">
                    <span>About</span>
                </a>
            </li>
            <li data-menuanchor="work">
                <a href="#work" class="icon-work">
                    <span>Work</span>
                </a>
            </li>
            <li data-menuanchor="contact">
                <a href="#contact" class="icon-contact">
                    <span>Contact</span>
                </a>
            </li>
            <li data-menuanchor="goodbye">
                <a href="#goodbye" class="icon-goodbye">
                    <span>Thank you</span>
                </a>
            </li>
        </ul>

@alvarotrigo
Copy link
Owner

As you can see in the living examples, it works well.
Your code looks good. The class should being added to the li element.

Sorry but I can not help you more with it. It is correct.

@andreyshipilov
Copy link
Author

Yep, not worries. If I find out what's wrong, I'll post here. Thanks anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants