/** * Created by Jeon on 2018-05-03. */ var productList = $(".pro_w >li"); var sliderRight = $("#slider-right"); var sliderLeft = $("#slider-left"); var indexPointer = 0; var marginLeft = 292; for(var i = 0; i < productList.length; i++) { var tempMargin = marginLeft * (i); productList.eq(i).css({"margin-left":tempMargin+"px"}) } sliderRight.click(function() { nextItem(); clearInterval(productListAutoSlider); productListAutoSlider = setInterval(function() { if(productList.length -4 - indexPointer >0) nextItem(); else if(productList.length -4 - indexPointer == 0) { moveFirst(); } },4000) }); sliderLeft.click(function() { previsionItem(); clearInterval(productListAutoSlider); productListAutoSlider = setInterval(function() { if(productList.length -4 - indexPointer >0) nextItem(); else if(productList.length -4 - indexPointer == 0) { moveFirst(); } },4000) }); function nextItem() { if(productList.length - 4 - indexPointer > 0) { indexPointer++; var tempLeft = indexPointer * -1 * marginLeft; productList.animate({"left":tempLeft+"px"},500); } } function previsionItem() { if(indexPointer > 0) { indexPointer--; var tempLeft = indexPointer * -1 * marginLeft; productList.animate({"left":tempLeft+"px"},500); } } function moveFirst() { indexPointer = 0; productList.animate({"left":0},500); } var productListAutoSlider = setInterval(function() { if(productList.length -4 - indexPointer >0) nextItem(); else if(productList.length -4 - indexPointer == 0) { moveFirst(); } },4000)