When the onLeave event of fullPage.js is activated

I am struggling to implement two CSS events when transitioning between sections on a fullPage.js application. To see my current progress, you can view the following fiddle: http://jsfiddle.net/pingo_/67oe1jvn/2/

My objectives are as follows:

  • To modify the class of the fa-stack icons to attributes upon leaving the page (currently the color changes only on click or hover, but I want it to change with scrolling)
  • To adjust the color of the navigation nodes to #ffffff when the background color is #004e7b (at present, the nodes are not visible in sections 2 and 4)

What would be the most effective way to accomplish this? In the JavaScript code snippet below, I have attempted to trigger an alert message upon leaving section one. However, this causes issues with scrolling and jumps directly to the last section:

var fromSection1 = false;
$('#fullpage').fullpage({       
  onLeave: function(index, direction){
     var leavingSection = $(this);
    //after leaving section 2
    if(index == 1 && direction =='down'){
      alert("Going to section 2!");
    }else{
      fromSection1 = false;
    }
  }
});

Similarly, how could I implement a change of class for the fa-nav sections? I'm unsure whether this change should be made in the CSS, JavaScript, or both. Working with class attributes is new to me, and I'm encountering difficulties with these tasks. Any guidance on the best approach and assistance would be greatly appreciated. Thank you!

Answer №1

You're currently working on an answer that was posted a year ago... The onLeave event now has 3 parameters instead of the previous two, as detailed in the documentation.

onLeave: function(index, nextIndex, direction){

In response to your queries, changing a class requires javascript. However, that might not be necessary for your situation.

Take a look at this informative video.

Remember that fullPage.js assigns the class active to the active section and adds the class fp-viewing-xxx to the body element, where xxx is the current section's anchor name or its index if no anchors are specified.

This enables you to manipulate the styling using CSS:

#demo{
    color: red;
} 

/* styles applied only to the section with the anchor `firstpage` */     
body.fp-viewing-firstpage #demo{
    color: blue;
} 

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

Is it possible to incorporate a jQuery widget within a table?

Can the jQuery sortable widget be utilized within a table, or is it designed to function separately? Here is the link to the jQuery widget for reference - http://jqueryui.com/sortable/#default ...

Encountering a Django Ajax HTTP 500 Error

I'm struggling to integrate Django with AJAX requests, and I keep getting an HTTP 500 error related to MultiValueDictKeyError even though everything seems fine? I passed in 3 variables: sendEmail, username, error When accessing request.POST on the 3 ...

Presentation for a div's background image with the use of jQuery

My header contains a large div with text contents and boxes, along with a background image. Now I want to create a slideshow for this div's background. Does anyone know how to make a slideshow for a div's background image? I've searched ex ...

Use jQuery to switch back and forth between the login and registration forms on a single

I've set up two forms, one for login and one for registration, with the default view showing the login form. There's a link that says "Don't have an account?" and when it's clicked, the registration form will display while the login for ...

Troubleshooting: Font-Face Won't Load on Any Browser

I'm completely new to using @font-face and I'm encountering some issues. Despite going through numerous posts and tutorials, I can't seem to get my fonts to load properly. I've tried activating and deactivating the font on the server, b ...

What steps do I need to take to activate this JQuery plugin successfully?

I stumbled upon this amazing silky smooth marquee jQuery plugin online @: Smooth marquee After downloading the latest JQuery and the JQuery marquee plugin as directed on the site above, I am still unable to make it work like they showcased in their demo: ...

Displaying and Concealing Divisions

My journey to showing/hiding divs began with piecing together a series of questions: $(document).ready(function(){ $('.box').hide(); $('#categories').onMouseOver(function() { $('.box').hide(); $('#div' + ...

Learning how to effectively incorporate two matSuffix mat-icons into an input field

I'm currently experiencing an issue where I need to add a cancel icon in the same line as the input field. The cancel icon should only be visible after some input has been entered. image description here Here's the code I've been working on ...

Strange Behavior of Delayed Responses in jQuery's Ajax Calls

Dealing with jQuery AJAX requests can be tricky, especially when the response is delayed. If I'm sending a request every second and the response takes, let's say, 3 seconds to come back, the success method of AJAX gets triggered. In Chrome Linu ...

What could be the reason for the selection box in my form not changing the items when togg

I'm having an issue with my form selection box code that used to work but is now not functioning properly. Could someone please help me identify where the error lies? Essentially, I have a form with the ID #main and a select box named #chart-type. Th ...

How can we avoid repeated evaluations by using memoization in a function?

Currently, I am working on a jQuery function designed to switch HTML elements based on specific viewports. The concept is quite simple: <div data-swap-for="#element" data-swap-on="phone"></div> This code snippet will insert the element with t ...

Elements floating in space, stretching across the entire width

In my design, I have a fixed size layout with a centered content container. My goal is to have the menu (home, about, contact, login) span 100% of the screen width. You can view the current setup in this jsfiddle: http://jsfiddle.net/Hxhc5/1/ I am aimin ...

Navigating on a stationary object: CSS Styling

I have a main div with another nested div inside. The nested div contains cards, but I am unable to scroll through them due to the fixed positioning of the main div. I need a way to enable scrolling for the cards within the nested div. Note that the presen ...

Searching for a column fails to yield any results after altering the value in

Here is a snippet of code that I am working with: <!DOCTYPE HTML> <html lang="en"> <head> <title> Exact matches overview </title> <script type="text/javascript" src="/static/s ...

Looking for tags similar to stackoverflow?

Is there a way to create a search box similar to the one in Tags where tag names are displayed immediately upon entering without pressing enter key? Could anyone provide me with a script or tutorial on how to achieve this? Is it done using JavaScript or j ...

How can we prevent the UL scroll animation from restarting in jQuery?

I've implemented a jQuery code with an AJAX function that updates 2 UL lists whenever the data on a WordPress page is changed. While the functionality works as expected, I'm facing an issue where the scroll animation restarts from the first LI e ...

Prevent webpage from resizing when window dimensions change

Whenever I resize my webpage window, the elements start to pile on top of each other and it looks disorganized. For example, when I reduce the window size, YouTube just cuts off everything instead of stacking the images. How can I achieve a similar effec ...

AngularJS Toggle Directive tutorial: Building a toggle directive in Angular

I'm attempting to achieve a similar effect as demonstrated in this Stack Overflow post, but within the context of AngularJS. The goal is to trigger a 180-degree rotation animation on a button when it's clicked – counterclockwise if active and c ...

Guide to utilizing SVG animations for line drawing rather than just outlines

I've been experimenting with animating an SVG file to resemble the gif below, and I'm getting pretty close, but I seem to be encountering an issue where the outlines are drawn before being filled. I want the entire lines to be animated as shown i ...

Encountering Internal Server Error (500) while attempting to send an ajax request to the controller

I am currently attempting to send data back from my view to the controller using an ajax request. The request is formulated as follows: $("body").on("click", "#AddProduct", function () { var id = $("#ProductDrop").val(); va ...