jQuery image slider glitch

Purva Shukla

When i click on the prev button twice, the picture disappears, and the slider doesn't work.

Here is my code: Jsfiddle link Any help will be appreciated. Thank you.

$(document).ready(function() {
    $('.nxt').on('click',function () {
        var currentImg = $('.active');
        var nextImg = currentImg.next();

        if(nextImg.length){
            currentImg.removeClass('active').css('z-index, -10');
            nextImg.addClass('active').css('z-index',10);
        }
    });

    $('.pre').on('click',function () {
        var currentImg = $('.active');
        var prevImg = currentImg.prev();

        if(prevImg.length){
            currentImg.removeClass('active').css('z-index, -10');
            prevImg.addClass('active').css('z-index',10);
        }

    });
  });
Sandeep Modak

When the currentImg.prev(); is being called its getting the previous element i.e "div" element with id="slider" in your case. Wrap your images in div as shown below:-

 <div>
   <img class="active" src="https://i.pinimg.com/564x/57/ab/87/57ab87058782698945270ad9f734ceb5.jpg">
    <img src="https://i.pinimg.com/564x/5f/fe/4c/5ffe4ca66086ec07e64b4a46e0e97026.jpg">
  </div>

Check the fiddle here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive