// JavaScript Document function tBans(obj) { var speed = obj.speed ? obj.speed : 300; var time = obj.time ? obj.time : 3000; var el=$(obj.element); var warp = el.children(".warp"); warp.append(warp.html()); var list = warp.children("a"); var len = list.length / 2; var width = parseInt(el.css("width")); list.css("width", width + "px"); var index = 0; var interval; $(window).resize(function () { var width = parseInt(el.css("width")); list.css("width", width + "px"); }); if(len<=1) return; for (var i = 0; i < len; i++) { if (i == index) el.children("ul").append('
  • '); else el.children("ul").append('
  • '); } var left = function () { if (index == 0) { index = len; warp.css("margin-left", -index * width + "px"); } index--; el.children("ul").children("li").removeClass("click").eq(index).addClass("click"); warp.animate({ "margin-left": -index * width + "px" }, speed); } var right = function () { index++; if (index == len) el.children("ul").children("li").removeClass("click").eq(0).addClass("click"); else el.children("ul").children("li").removeClass("click").eq(index).addClass("click"); warp.animate({ "margin-left": -index * width + "px" }, speed, function () { if (index == len) { index = 0; warp.css("margin-left", -index * width + "px"); } }); } interval = setInterval(right, time); el.children("span").click(function () { clearInterval(interval); if ($(this).hasClass("tr")) { right(); } else { left(); } interval = setInterval(right, time); }); el.children("ul").children("li").each(function (i) { $(this).click(function () { clearInterval(interval); index = i; el.children("ul").children("li").removeClass("click").eq(index).addClass("click"); warp.animate({ "margin-left": -index * width + "px" }, speed); interval = setInterval(right, time); }); }); var startX = 0, startY = 0; var moveX = 0, moveY = 0; el[0].addEventListener('touchstart', function (e) { return start(e); }, false); el[0].addEventListener('touchmove', function (e) { return move(e); }, false); el[0].addEventListener('touchend', function (e) { return end(e); }, false); var start = function (e) { clearInterval(interval); var point = e.touches ? e.touches[0] : e; startX = point.screenX; startY = point.screenY; } var move = function (e) { e.preventDefault(); var point = e.touches ? e.touches[0] : e; x = point.screenX; y = point.screenY; moveX = x - startX; moveY = y - startY; startY = y; } var end = function (e) { if (moveX < -50) { right(); } if (moveX > 50) { left(); } interval = setInterval(right, time); } }