$(document).ready(function() { var $sliders = $(".bview"), $slidebgs = $(".slides__bg"), diff = 0, curslide = 0, numofslides = $(".slides").length-1, animating = false, animtime = 800, autoslidetimeout, autoslidedelay = 6000, $pagination = $(".bview-pagi"); function createbullets() { for (var i = 0; i < numofslides+1; i++) { var $li = $("
"); $li.addclass("bview-pagi__elem-"+i).data("page", i); if (!i) $li.addclass("active"); $pagination.append($li); } }; createbullets(); function autoslide() { autoslidetimeout = settimeout(function() { curslide++; if (curslide > numofslides) curslide = 0; changeslides(); }, autoslidedelay); }; autoslide(); function changeslides(instant) { if (!instant) { animating = true; //managecontrols(); $sliders.addclass("animatingg"); // $slider.css("top"); $(".slides").removeclass("active"); $(".slides-"+curslide).addclass("active"); settimeout(function() { $sliders.removeclass("animatingg"); animating = false; }, animtime); } window.cleartimeout(autoslidetimeout); $(".bview-pagi__elem").removeclass("active"); $(".bview-pagi__elem-"+curslide).addclass("active"); $sliders.css("transform", "translate3d("+ -curslide*100 +"%,0,0)"); diff = 0; autoslide(); } function navigateleft() { if (animating) return; if (curslide > 0) curslide--; changeslides(); } function navigateright() { if (animating) return; if (curslide < numofslides) curslide++; changeslides(); } $(document).on("mousedown touchstart", ".bview", function(e) { if (animating) return; window.cleartimeout(autoslidetimeout); var startx = e.pagex || e.originalevent.touches[0].pagex, winw = $(window).width(); diff = 0; $(document).on("mousemove touchmove", function(e) { var x = e.pagex || e.originalevent.touches[0].pagex; diff = (startx - x) / winw * 70; if ((!curslide && diff < 0) || (curslide === numofslides && diff > 0)) diff /= 2; $sliders.css("transform", "translate3d("+ (-curslide*100 - diff) +"%,0,0)"); }); }); $(document).on("mouseup touchend", function(e) { $(document).off("mousemove touchmove"); if (animating) return; if (!diff) { changeslides(true); //0000000 return; } if (diff > -8 && diff < 8) { changeslides(); return; } if (diff <= -8) { navigateleft(); } if (diff >= 8) { navigateright(); } }); $(document).on("click", ".bview-pagi__elem", function() { curslide = $(this).data("page"); changeslides(); }); });