Answer the question
In order to leave comments, you need to log in
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);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question