Federico
Federico

Reputation: 1422

Get current slide on fullpage.js

I'm a happy Fullpage.js user!
I just would love to add a class (.num) that shows the current number of slide / the total number of slides.

I'm using this function that works fine, the problem is that it doesn't update at slide change.

$('.section').each(function(){
    var section = $(this),
    sectionSlides = section.find('.slide'),
    totalItems = sectionSlides.length,
    currentIndex = sectionSlides.filter('.active').index() + 2,
    numContainer = section.find('.num');

numContainer.html(currentIndex + ' / ' + totalItems);
});

http://jsfiddle.net/168xofn3/11/

Upvotes: 3

Views: 10324

Answers (2)

Alvaro
Alvaro

Reputation: 41595

Three ways:

Upvotes: 7

Federico
Federico

Reputation: 1422

I belive that this code can solve my problem I just have to change that alert maybe?

$('#fullpage').fullpage({
    onSlideLeave: function( anchorLink, index, slideIndex, direction, nextSlideIndex){
        var leavingSlide = $(this);

        //leaving the first slide of the 2nd Section to the right
        if(index == 2 && slideIndex == 0 && direction == 'right'){
            alert("Leaving the fist slide!!");
        }

        //leaving the 3rd slide of the 2nd Section to the left
        if(index == 2 && slideIndex == 2 && direction == 'left'){
            alert("Going to slide 2! ");
        }
    }
});

Upvotes: 0

Related Questions