var slider = { el: { slider: $(".why-chose-selection .elementor-container, .value-container .elementor-container"), holder: $(".why-chose-selection .elementor-row, .value-container .elementor-row"), }, totalSlide: 3, slideWidth: $(window).width(), touchstartx: undefined, touchmovex: undefined, movex: undefined, index: 0, longTouch: undefined, init: function () { this.bindUIEvents(); }, bindUIEvents: function () { this.el.holder.on("touchstart", function (event) { slider.start(event); }); this.el.holder.on("touchmove", function (event) { slider.move(event); }); this.el.holder.on("touchend", function (event) { slider.end(event); }); }, start: function (event) { this.touchstartx = event.originalEvent.touches[0].pageX; $(".animate").removeClass("animate"); }, move: function (event) { this.touchmovex = event.originalEvent.touches[0].pageX; this.movex = this.index * this.slideWidth + (this.touchstartx - this.touchmovex); if (this.movex < this.slideWidth * this.totalSlide) { this.el.holder.css("transform", "translate3d(-" + this.movex + "px,0,0)"); } }, end: function (event) { var absMove = Math.abs(this.index * this.slideWidth - this.movex); if (absMove > this.slideWidth / 2 || this.longTouch === false) { if (this.movex > this.index * this.slideWidth && this.index < this.totalSlide) { this.index++; } else if (this.movex < this.index * this.slideWidth && this.index > 0) { this.index--; } } this.el.holder .addClass("animate") .css( "transform", "translate3d(-" + this.index * this.slideWidth + "px,0,0)" ); }, }; slider.init();