Retrieve the current slide and emphasize the matching number in the counter

For my upcoming website, I have decided to incorporate Fullpage.js. Take a look at the live example below. My objective is to be able to manage the #num that gets generated by the Javascript code provided here.

The idea is to emphasize every number that corresponds to the currently displayed slide.

Hence:
Slide number 1: 01 02 03 04 05
Slide number 2: 01 02 03 04 05
. . .

I would appreciate any assistance with this matter.

$(document.body).ready(function(){$('#fullpage').fullpage({
                afterLoad:function(index, nextIndex, direction){
                    var str = "";
                    var n = $( ".fp-section.active .fp-slide" ).length + 1;
                    for (var x = 1; x < n ; x++) {
                        str = str + 0 + x + "\u00A0\u00A0";
                    }
                    $("#num").text(str);
                }
            });});
body{
                font-family:arial;
                background:black;
                color:white;
                text-align:center;
            }
            #num{
                position:fixed;
                width:100%;
                right:0;
                bottom:12px;
                z-index:10006; 
                font-size:21px;
            }
            .slide{
                line-height:100vh;
                text-align:center;
                font-size:100px;
            }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://alvarotrigo.com/fullPage/jquery.fullPage.css" rel="stylesheet"/>
<script src="http://alvarotrigo.com/fullPage/jquery.fullPage.min.js"></script>

<div id="fullpage">

<div class=section id=section1>
<div class=slide>01</div>
<div class=slide>02</div>
<div class=slide>03</div>
<div class=slide>04</div>
</div>

<div class=section id=section2>
<div class=slide>01</div>
<div class=slide>02</div>
<div class=slide>03</div>
</div>
  
</div>
<div id="num"></div>

Answer №1

$(document).ready(function(){
  $('#fullpage').fullpage({
    afterLoad: function(index, nextIndex, direction){
      $("#num").html("");
      var slide = nextIndex;
      var str = "";
      var n = $( ".fp-section.active .fp-slide" ).length + 1;
      for (var x = 1; x < n ; x++) {
        str = "<span class='slide-num slide-num-"+ x +"'>"+ 0 + x + "</span>";
        $("#num").append(str);
      }
      updateNavigation(slide);
    },
    onSlideLeave: function(anchorLink, index, slideIndex, direction, nextSlideIndex){
      var slide = nextSlideIndex+1;
      updateNavigation(slide);
    }
  });
    
  function updateNavigation(slide) {
    $('.slide-num').removeClass('active');
    $('.slide-num-'+ slide).addClass('active');
  }
});
body{
  font-family:arial;
  background:black;
  color:white;
  text-align:center;
}
#num{
  position:fixed;
  width:100%;
  right:0;
  bottom:12px;
  z-index:10006; 
  font-size:21px;
}
.slide{
  line-height:100vh;
  text-align:center;
  font-size:100px;
}
.slide-num {
  display: inline-block;
  margin: 0 5px;
}
.slide-num.active {
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://alvarotrigo.com/fullPage/jquery.fullPage.css" rel="stylesheet"/>
<script src="http://alvarotrigo.com/fullPage/jquery.fullPage.min.js"></script>

<div id="fullpage">

<div class=section id=section1>
<div class=slide>01</div>
<div class=slide>02</div>
<div class=slide>03</div>
<div class=slide>04</div>
</div>

<div class=section id=section2>
<div class=slide>01</div>
<div class=slide>02</div>
<div class=slide>03</div>
</div>
  
</div>
<div id="num"></div>

Answer №2

I am currently here and everything is working smoothly with the resetSlider plugin. I really want to ensure a seamless transition for that #num.

$(function (){$('#fullpage').fullpage({
onLeave: function(index, nextIndex, direction){
    $('.slide-num').addClass("via");
},
afterLoad:function(index, nextIndex, direction){
    var str = "";
    var n = $( ".fp-section.active .fp-slide" ).length + 1;
    for (var x = 1; x < n ; x++) {
      str = "<li class='slide-num slide-num-"+ x +"'>"+ 0 + x + "</li>";
      $("#num").append(str);
    }
    $('.slide-num-1').addClass('attivo');
    },
onSlideLeave: function(anchorLink, index, slideIndex, direction, nextSlideIndex){
    var slide = nextSlideIndex+1;
    $('.slide-num').removeClass('attivo');
    $('.slide-num-'+ slide).addClass('attivo');
}
});});
body{
  font-family:arial;
  background:black;
  color:white;
  text-align:center;
}
#num{
  position:fixed;
  width:100%;
  right:0;
  bottom:12px;
  z-index:10006; 
  font-size:21px;
}
.slide{
  line-height:100vh;
  text-align:center;
  font-size:100px;
}
.slide-num {
  display: inline-block;
  margin: 0 5px;
  opacity:.2;
}
.attivo {
  opacity: 1;
}
.via{
  display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://alvarotrigo.com/fullPage/jquery.fullPage.css" rel="stylesheet"/>
<script src="http://alvarotrigo.com/fullPage/jquery.fullPage.min.js"></script>

<div id="fullpage">

<div class=section id=section1>
<div class=slide>01</div>
<div class=slide>02</div>
<div class=slide>03</div>
<div class=slide>04</div>
<div class=slide>05</div>
<div class=slide>06</div>
<div class=slide>07</div>
<div class=slide>08</div>
</div>

<div class=section id=section2>
<div class=slide>01</div>
<div class=slide>02</div>
</div>

<div class=section id=section3>
<div class=slide>01</div>
<div class=slide>02</div>
<div class=slide>03</div>
<div class=slide>04</div>
<div class=slide>05</div>
<div class=slide>06</div>
</div>
  
</div>
<div id="num"></div>

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

Display loading icon in AngularJS during template retrieval

Imagine I have this specific directive: angular .module('app.widgets') .directive('myCalendarRange', myCalendarRange); function myCalendarRange () { var directive = { link: link, templateUrl: '/template/is/located ...

Tips for updating and transferring a variable within a callback function

I have implemented a function using the SoundCloud API that retrieves a song URL, obtains the associated sound ID from the API, and then passes that ID to a callback for streaming purposes and updating the page. The data is successfully retrieved from the ...

What is the best way to show an error message on a field when using a custom form validator?

In my JavaScript code, I have created a form validator that is capable of validating different input fields based on specific attributes. However, I need assistance with implementing error handling and scrolling to the erroneous field. For each <input& ...

Interactive sign-in/sign-out navigation bar

I need the login button to show as log out when the user is logged in. In the index.js file: app.get('/', (request, response) => { const isAuthenticated = request.session.authenticated || false; // { user: { authenticated: isAuthenti ...

Having trouble grasping the intricacies of using EventEmitter with webpack and es6 modules

As I delve into learning webpack and ES6 simultaneously, I've come to the realization that I need an event bus. Even though I'm new to EventEmitters and constructors, I have gone through the documentation and numerous examples. However, I can&apo ...

An absolutely positioned element will always move within its relative container

After extensive searching on Google and Stack Overflow, I finally found what seemed like the perfect solution. The logic behind it made sense and I understood it perfectly. But when I implemented it, my absolute positioned divs kept moving whenever I resiz ...

Ways to incorporate transparency into the background color

Is there a way to make the following CSS statement partially transparent? background: none repeat scroll 0 0 #205081; If CSS2 doesn't support it, how can I add an opacity declaration in CSS3? ...

When the window is scrolled to 50%, I would like to load some additional data

Looking to load data when the browser scrollbar reaches 50%... In jQuery, I created the following function: $(window).on('scroll', function () { alert("scrolling"); if ($(window).scrollTop() + $(window).innerHeight() > ...

How does the performance contrast between "skip if condition" and "immediately return"?

Do you know if there is a performance variance between these two functions? function x() { var x = false; if(x == true) { ... Numerous lines, like 1 million ... } } function y() { var x = false; if (x != true) { retu ...

Display or Conceal Content Depending on the Button's Status

I am currently working on implementing an accordion style button for a project. I have configured my component to hide the list when the button is clicked, but I am encountering an issue where the list does not reappear. Additionally, I would like to inc ...

Tips for implementing a dynamic value in the ng-style based on certain conditions

Is there a way to set a background-color conditionally using ng-style when the color value can be updated from $scope? These are the variables in my scope: $scope.someone = { id: '1', name: 'John', color: '#42a1cd' }; $scope ...

Determining the live total number of Protovis Sparkbar instances

I am currently working on a project where I need to show the ratings and corresponding dates (in string format) from a JSON file in tipsy tooltips. The data consists of a list of dates and ratings. For example: var data = [{"dates":["2010-07-01","2010-07 ...

Unfortunately, Protractor does not support MouseMove in Firefox browser

I'm fairly new to using protractor and selenium. I've been attempting to replicate the mouse hover action on a button and retrieve values like the position of the mouse pointer and background colors. When I use mousemove, it works perfectly in Ch ...

Transforming a collection of nested objects from Firebase into an array in JavaScript/Typescript

In my Ionic3 / Angular4 application, I am utilizing Firebase. The structure of the data in Firebase Realtime Database is as follows: Using the TypeScript code below, I am fetching observable data from Firebase... getDishesCategories(uid: string) { ...

What could be causing these strange white lines to show up on my AFrame meshes?

When I import a GLB scene with baked textures into A-Frame using THREE.js, I am experiencing an issue where white lines appear on my objects (pictured below). The walls are grouped meshes which may explain the lines appearing there, but I am puzzled as to ...

I've encountered an issue in my Django project when trying to submit a form. Can someone help me identify and fix the error?

Oops! An Error Occurred We couldn't find the page you're looking for (Error 404). Request Method: POST Request URL: http://localhost:8000/contact/contact Using the URLconf defined in portfolio.urls admin/ [name='home'] about/ [name= ...

Ionic 4 Tabs with Smooth Scrolling

I recently started using Ionic 4 and I'm trying to create scrollable tabs in Ionic 4. However, when I include multiple tabs as shown in the code below, they become compressed and appear within the same viewing space. <ion-tab-bar slot="top"> ...

Tips on accessing the text content of a dt element with prototype

Below is some HTML code that I am working with: <dl> <dt><label>test</label></dt> <dd><input id="someid" type="checkbox" onchange="opConfig.reloadPrice()" class="product-custom-op ...

Creating mutual reactivity between two inputs in Vue.js

I am in the process of creating a tool that calculates the cost of purchasing specific materials. One challenge I'm facing is that users sometimes buy by mass and other times by volume. My goal is to have two active input fields (one for mass and one ...

sophisticated authorization structure for sails.js and angular

Thinking about developing some applications using sails.js and angular.js I'm in search of a way to create adaptable permissions. I want the ability to control permissions for model operations (CRUD) and functions within models. Additionally, it shou ...