fullpage.js supports triggering multiple onLeave and afterLoad events for different sections

I'm facing an issue while trying to incorporate multiple afterLoad and onLeave events in my fullpage.js for different sections. It seems like only the last one I set up is functional. What could be causing this problem?

Interestingly, when I remove the last event, the first one works as expected. This indicates that I might be combining them incorrectly, causing one to override the other.

$('#fullpage').fullpage({
      onLeave: function(index, nextIndex, direction) {
          if (nextIndex == 3 || nextIndex == 1) {
              $('.aboutme').hide("slide", {
                  direction: "left"
              }, 200);
          }


      },
      afterLoad: function(anchorLink, index) {
          if (index == 2) {
              $('.aboutme').show("slide", {
                  direction: "left"
              }, 200);
          }

      },

      onLeave: function(index, nextIndex, direction) {

          if (nextIndex == 2) {
              $('.titlea').hide("slide", {
                  direction: "right"
              }, 200, function() {
                  $('.titleb').hide("slide", {
                      direction: "right"
                  }, 200);
              });
          }

      },
      afterLoad: function(anchorLink, index) {

          if (index == 1) {
              $('.titlea').show("slide", {
                  direction: "right"
              }, 200, function() {
                  $('.titleb').show("slide", {
                      direction: "right"
                  }, 200);
              });
          }
      }
  });

Can you guide me on the correct approach to combine multiple onLeave and afterLoad methods effectively?

Answer №1

If you already have if clauses in your event functions, you can try the following approach:

$('#fullpage').fullpage({
        onLeave: function(index, nextIndex, direction){                
            if (nextIndex == 3 || nextIndex == 1 ) {
                $('.aboutme').hide("slide", { direction: "left" }, 200);
            } else if (nextIndex == 2 ) {
                $('.titlea').hide("slide", { direction: "right" }, 700, function(){$('.titleb').hide("slide", { direction: "right" }, 200);});
            }
        },
        afterLoad: function(anchorLink, index){
            if (index == 2){
                $('.aboutme').show("slide", { direction: "left" }, 200);
            } else if (index == 1 ) {
                $('.titlea').show("slide", { direction: "right" }, 700, function(){$('.titleb').show("slide", { direction: "right" }, 200);});
            }
        }   

    });   

});

Alternatively, you can use switch/case like this:

$('#fullpage').fullpage({
        onLeave: function(index, nextIndex, direction){  
            switch(nextIndex){
                case 3:
                case 1:
                    $('.aboutme').hide("slide", { direction: "left" }, 200);
                    break;
                case 2:
                    $('.titlea').hide("slide", { direction: "right" }, 700, function(){$('.titleb').hide("slide", { direction: "right" }, 200);});
                    break;
            }
        },
        afterLoad: function(anchorLink, index){
            switch(index){
                case 2:
                    $('.aboutme').show("slide", { direction: "left" }, 200);
                    break;
                case 1:
                    $('.titlea').show("slide", { direction: "right" }, 700, function(){$('.titleb').show("slide", { direction: "right" }, 200);});
                    break;
            }
        }   

    });   

});

In essence, you have one event callback function, and based on the parameters passed, decisions are made on the actions to be taken.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Scrolling to a specific position on a page when a Vue 3 component appears is a must-do for

When I click a button, my basic form component appears without using the router. I would like the scroll position of the form to automatically move down slightly (for example, on the y-axis at 40) once it is displayed. However, I am unsure of how to achi ...

Safari-exclusive: Google Maps API dynamically altering page aesthetics post-loading

Recently, I encountered a peculiar problem. Upon loading a page, the text displayed with full opacity. However, upon the Google Maps API loading after 2 seconds, the entire page's styling suddenly changed. It was as if the text on the page became less ...

Prevent users from inputting multiple minus signs by setting the input type to number and disabling the

Is there a way to prevent the input type number from accepting "--" as input? I am looking for a solution to disable this behavior. Additionally, the input field seems to allow for various incorrect formats like: -12-12 -- -121- 23-323- ...

Regular Expressions in action - Substituting text within an eZ Publish XML field

Before utilizing the eZ Publish 5 API to create an Xml content, I need to make some modifications. I am currently working on implementing a Regex to edit the content. Below is the Xml code I have (with html entities) : View Xml code here http://img15.ho ...

Discovering a way to capture the space bar event in a number input field with JavaScript

Is there a way to capture space bar input with an onchange event in JavaScript? <html> <head> <script type = "text/javascript"> function lala(aa){ console.log(aa + " dasda"); } </script> </head> <body> <input ty ...

Unable to access information in node.js due to an Ajax POST request issue

I am seeking assistance with a seemingly simple issue that I am struggling to resolve. I have an ajax post request that successfully sends data to a node.js server. While it appears that the server is receiving the data, I am unable to access the data fiel ...

Changing the orientation of a dropdown menu from horizontal to vertical

Hello, I am seeking assistance to transform the top dropdown menu layout into a vertical one similar to the menu on the left side. Any help would be greatly appreciated as I am running out of ideas! Thank you in advance! @charset "utf-8"; /* CSS Docum ...

Initiate the printing process by executing the window.print() function. As the document is being

Here's the code snippet : <body> <div class="headerCont noprint"> <div class="headerHold"> <div class="logoCont"><img src="images/logo.jpg" width="104" height="74" alt="Logo"> ...

Need to return false even though Jquery form check currently returns true

Upon form submission, the following check is executed: if((formData[4].value == 1 || formData[4].value == 2) && !formData[2].value) { alert('Please fill out the key field'); return false; } else { $.ajax({ url: "/aja ...

Choose from the select2 multiselect options and lock certain selected choices from being altered

I have coded a select dropdown with preselected options, some of which I want to keep fixed so that users cannot change them. To achieve this, I implemented the following code: <select id="select2-multiple" name="users" multiple="multiple" style="width ...

What is a creative way to get rid of old content on a webpage using jQuery without relying on the

As I work on my crossword project, I have almost completed it, but encountering a problem. Within my HTML code, I have a select list that loads a .JSON file using Javascript. <form method="post" id="formulaire"> <div class="toto"> <sel ...

Is it possible to eliminate certain JavaScript code by clicking on something?

I've been searching for a solution to this issue without any luck. Currently, I have two main JavaScript functions running on a website I'm developing. One is for lazy loading images and the other is for smooth scrolling to an anchor link at the ...

Can a JavaScript framework be created to ensure all browsers adhere to standards?

As someone who isn't an expert in JavaScript, I wonder if it's feasible to create a comprehensive embeddable JavaScript file that ensures all browsers adhere to standards. Could there be a compilation of known JavaScript hacks that compel each br ...

Connecting PHP modules for AJAX requests: a guide to linking files in PHP

If I have a file structure like the following: / index.php // contains database connection, login details, ... ... /someSubSite content_someSite.html // basic layout, text, forms, ... styles_someSite.css // styling for cont ...

Section separators within ordered lists

I am currently working on creating a "reference document" section within a Webhelp Responsive website that I have developed using a DITA map. My goal is to display a typical document list with unique reference numbers ([1], [2], [3]...[N]) followed by rele ...

Incorporate the variables specified in the parent PHP file into the PHP code being received through

I am currently working on a project that involves enabling a user to view his profile upon login. However, I am aiming to have the dashboard load all other profile pages through ajax, such as the view profile and edit profile pages. My progress so far inc ...

Updating information in mysql from html/php can sometimes be a complex process

The issue I am facing involves a "contact" form that is supposed to send data to my database. Everything seems to be working fine with no errors when I access the page from localhost, and it displays the desired result. However, the database (localhost/php ...

Incorporating local JSON data into HTML: A Step-by-Step

I'm completely new to javascript and the utilization of json. What I want to accomplish is quite straightforward, although I am encountering difficulties. My objective is to create a website consisting of two pages: one that showcases artists and ano ...

What is the best way to attach an event listener to detect the coordinates where a click occurs inside a div element?

Imagine a situation where you have a div container measuring 200px by 500px. The goal is to implement an event listener that can identify the x and y coordinates within this div when it is clicked. What would be the approach to achieve this in React? ...

Retrieving an HTML string in an Ajax request

When I make an ajax call to retrieve an HTML string, the response includes the complete HTML of the current page instead of just the HTML I am generating in the web method. Here is my code: $.ajax({ type: "GET", url: ' ...