V
V
viklenko2017-11-13 21:59:00
Slider
viklenko, 2017-11-13 21:59:00

How to make the slider scroll its object and not everything on the page?

(function ($) {
    $.fn.slide = function () {
        var imgWidth = $(this).children().children().width();
        var imgInBlock = Math.ceil(($(this).width() / imgWidth) + 1); //
        var lengthSlide = 1;
        console.log(this[0].children);
        var curWidth = 0; //
        var totalImage = $('.slidewrapper').children().length; //
        var curImg = 0;

        $('.next-btn').click(function () {
            if (curImg <= totalImage - (imgInBlock)) {
                curWidth -= imgWidth * lengthSlide;
                $('.slidewrapper').css('transform', 'translate' + '(' + curWidth + 'px)');
                curImg++;
            }
        })

        $('.prev-btn').click(function () {
            if (curImg > 0) {
                curWidth += imgWidth * lengthSlide;
                $('.slidewrapper').css('transform', 'translate' + '(' + curWidth + 'px)');
                curImg--;
            }
        })


    };
})(jQuery);

A photo
spoiler
SVuoDVeg.jpg

As you can see, there are two blocks with an image slide on the page, and now the script scrolls through all these blocks, but you need to make it scroll only its own block. The class names are the same, how to do it? through selectors? if so, how, I tried it through this, it doesn't work

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question