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 there a way to customize the scrollbar color based on the user's preference?

Instead of hardcoding the scrollbar color to red, I want to change it based on a color variable provided by the user. I believe there are two possible solutions to this issue: Is it possible to assign a variable to line 15 instead of a specific color lik ...

Exploring the ancestors of an element

JS <script> $('.btn').click(function(e){ target = e.target; parent = target.parentNode.parentNode; console.log(parent); }); </script> HTML <div class="card" sty ...

How can I use Bootstrap and PHP to style future posts in separate rows on a website?

I am attempting to design a categories navigation menu using Bootstrap 5. It consists of two columns, the first displaying featured posts and the second showing 5 recent posts. Here is an example of what I have tried, but it didn't work as expected b ...

Tips for personalizing the color scheme of Material UI Stepper Step?

I need help customizing the disabled Step color for Material UI Steppers. The default colors are Blue for enabled steps and Grey for disabled steps, but I want to change it to a different color as shown in this example: https://i.stack.imgur.com/HGGxp.png ...

The pqselect plugin in jquery is malfunctioning without any visible errors

I'm really struggling to get this plugin to work. It's the jQuery pqselect plugin for creating multiple select boxes with checkboxes. Even though I've followed the usage instructions, it still doesn't seem to be functioning correctly. ...

AJAX in jQuery cannot be used to send data to a PHP

I am facing an issue with my script that uses AJAX to post data to the server and display it, but unfortunately, it is not functioning properly... Here is the current output: Your viewport width is 1332x670 Ajax initialization failed! In this scenario, ...

What is the best way to create a div that maintains a consistent size while displaying images inside?

Struggling with a project and attempting to create a fixed div container for uniform picture sizes, I've tested various methods recommended by others but have had zero success in altering the size of my div container. Could it be due to my use of boot ...

Tips for preserving changes made to a jQuery script when the page is reloaded

Is there a way to retain jQuery script changes when the page is reloaded? I have a page where clicking on certain elements triggers events, and I want these changes to persist even after reloading the page, resetting only when the cache is cleared. I appre ...

What's the best way to ensure these have equal heights?

There seems to be a difference in height between the verses at the bottom, and I want each verse next to each other to have equal heights. Here is my current code setup: .verse img { height: 1em; } <h1>PSALM 1</h1> <p> <div> ...

CSS - setting the background-image property is not displaying the image

.main_banner { background-image: url("../images/main_banner.png"); width: 100%; height: auto; } <!DOCTYPE html> <html> <heading> <title> ********** </title> <link rel="sty ...

Is it possible to incorporate a fadein animation into a function?

Developing the entire HTML structure using JavaScript is one of my skills. Here is a snippet as an example: function generateHeader () { $('body').append( $('<header>') .attr('id', "main-header") ...

Transform ISO-8859-1 encoding into UTF-8

Recently, I encountered an issue while sending a HTTP request using jQuery's ajax. The server, unfortunately, returns the response in ISO-8859-1 format while my page is set to UTF-8. This discrepancy causes some characters to become unreadable. How ...

Customizing Geonames JSON Ajax Request

Having found the code I needed from a sample website, I am now seeking help to customize it to only display results from the USA. This is the current code snippet: $(function() { function log( message ) { $( "<div>" ).text( message ).pr ...

Refresh HTML table when database is updated

My panel has a user table which is populated using the following snippet of Php code : <html> <body> <div id="order_table"> <table> <thead> <tr> <th>Name</th> < ...

Ways to customize the appearance of a search box

I am looking to revamp the appearance of a search bar that currently looks like this: <div class="searchbase input-group animated trans" id="searchbase"> <input type="text" placeholder="<?php _e(_l('Searching...'));?>" class=" ...

Ensure portrait orientation images have a restricted width to maintain their aspect ratio

On a responsive site, I have set up flexslider to showcase both landscape and portrait orientation images. The smoothHeight: true option is enabled to adjust the height according to the images. However, at the largest media query where the flexslider cont ...

Is it possible to have a hidden div box within a WordPress post that is only visible to the author of the

How can I create a div box with "id=secret" inside a post that is only visible to the author of the post? I initially made it for the admin, but now I want the id to be visible exclusively to the post's author. For instance: If the author is curren ...

Using a function to identify and check dynamically added checkboxes

I am using a PHP page that loads a group of categories from another PHP script as checkboxes. Here is the format for the checkboxes: <input type='checkbox' class='cat-selector' id='Business' data-toggle='checkbox&apo ...

Utilize jQuery selectors to target elements on a web page that has been stored in a variable

Currently, I am in the process of developing a Greasemonkey script that involves using JQuery. As part of this project, I am loading multiple pages into variables and successfully retrieving them using $.get. One challenge I have encountered is figuring o ...

What is the best way to vertically center all content, including borders, within the columns?

To view the codepen for reference, please click on the following link: http://codepen.io/rezasan/pen/apvMOR I am attempting to align all the content within the columns (Date, Title, and Button, including the separator) vertically. I have tried using displ ...