$(".box>ul>li").on("touchstart", function(event) { var startX = 0; var moveX = 0; var endX = 0; var bi = 0; var e = event || window.event; e.preventDefault(); startX = e.originalEvent.changedTouches[0].pageX; var mgl = parseInt($(this).css("marginLeft")); if (mgl == 0) { $(this).on("touchmove", function(event) { var e = event || window.event; e.preventDefault(); moveX = e.originalEvent.changedTouches[0].pageX; if (startX < moveX) { $(this).css("marginLeft", "0%"); } else if (startX > moveX) { bi = ((startX - moveX) / $(".box>ul").width()) * 100; if (bi > 20) { bi = 20; } $(this).css("marginLeft", -bi + "%"); } }); } else if (mgl < 0) { $(this).on("touchmove", function(event) { var e = event || window.event; e.preventDefault(); moveX = e.originalEvent.changedTouches[0].pageX; if (startX > moveX) { $(this).css("marginLeft", "-20%"); } else if (startX < moveX) { bi = ((moveX - startX) / $(".box>ul").width()) * 100; if (bi > 20) { bi = 20; } $(this).css("marginLeft", -20 + bi + "%"); } }); }
$(this).on("touchend", function(event) { var aa = bi; var e = event || window.event; e.preventDefault(); endX = e.originalEvent.changedTouches[0].pageX; if (mgl == 0) { if (startX > endX && aa > 10) { aa = 20; } else { aa = 0; } $(this).css("marginLeft", -aa + "%"); } else if (mgl < 0) { if (startX < endX && aa > 10) { aa = 20; } else { aa = 0; } $(this).css("marginLeft", -20 + aa + "%"); } }); });
|