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

Changing Moveto destination depending on the current page index or anchor. #4528

Open
obemer opened this issue Mar 16, 2023 · 3 comments
Open
Labels

Comments

@obemer
Copy link

obemer commented Mar 16, 2023

Hello,

First of all thank you very much for fullpage.js.
It's been a blast so far.

I can't find a solution to my problem, and that's because I'm a beginner at writing in javascript.
Anyway.

I created an onclick function to create a button on my page. And it works great.

$(document).on('click', '#infos', function(){
fullpage_api.moveTo('home', 1);
});

However, I would like to use the same button to go back where I was before I clicked it.
I click the button -> I go to a certain slide -> I click it again and I go back to the section/slide previously opened.

Is that even possible ?
If not, I would consider an option such as:
I click the button -> I go to a certain slide -> I click it again and I go to an other slide.

I tried this

$(document).on('click', '#infos', function(section, origin, destination, direction, trigger){

   if(section.anchor == 'home/2'){
		fullpage_api.silentMoveTo('works');
  }
  		else{
  		fullpage_api.silentMoveTo('home', 1);
  		}
});

I only get the 'else' condition to work. I'm pretty sure that I wrote that wrong.

Help would be appreciated.
Many thanks .

Olivier

@alvarotrigo
Copy link
Owner

I click the button -> I go to a certain slide -> I click it again and I go back to the section/slide previously opened.

Is that even possible ?

Many things are possible with the right knowledge ;)

All you have to do is record what was the active section index when you click the button, save it into a variable, and then use that value whenever you click on the button again.

@alvarotrigo
Copy link
Owner

For general JavaScript queries, you might want to consider asking in other places such as https://stackoverflow.com/ where they'll be able to help you much better.

@obemer
Copy link
Author

obemer commented Mar 17, 2023

Thank you ! I'll try to find the answer on stackoverlow then.

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

No branches or pull requests

2 participants