How to make the slider not catch the last element?

0

I would like to know how to resolve the following case.

I have a structure as follows:

<section class="portfolio slide" id="portfolio">
    <h2>portfólio.</h2>
    <div id="foto">
        <img src="images/img-1.jpeg" alt="imagem 1" />
    </div>
    <div id="foto">
        <img src="images/pexels-photo.jpg" alt="imagem 2" />
    </div>
    <div id="foto">
        <img src="images/img-1.jpeg" alt="imagem 3" />
    </div>
    <div class="botao">
        <a href="#" class="botao-portfolio">
            <i  class="far fa-eye"></i>
            veja mais.
        </a>
    </div>
</section>

I want to make a slider that rotates the photos in <div> with id="foto" , however my code is "catching" <div> with class="botao" . I wonder if it is possible to not "catch" last <div> . Thanks!

The following is the jQuery code:

function slider(sliderName) {
    var sliderClass = '.' + sliderName,
        activeClass = 'active';

    $('.slide > #foto:first').addClass('active');

    function rotateSlide() {
        var activeSlide = $(sliderClass + ' > .' + activeClass),
            nextSlide = activeSlide.next();

        if(nextSlide.length == 0) {
            nextSlide = $(sliderClass + ' > :first');
        }
        activeSlide.removeClass(activeClass);
        nextSlide.addClass(activeClass);
    }
}

slider('portfolio');
    
asked by anonymous 16.10.2018 / 23:03

1 answer

2

Just use nextSlide = activeSlide.next('#foto'); this way instead of returning the next element, your query will only return the next element with id equal to the photo.

Just a note: Do not give the same id for two elements of your DOM, ids must be unique, this can cause various types of errors. Instead of having multiple elements with the photo id, have multiple elements with the photo class, and make queries using ".photo" instead of "#photo".

    
16.10.2018 / 23:52