window.onload = function () { (function (d) { var ce = function (e, n) { var a = document.createEvent("CustomEvent"); a.initCustomEvent(n, true, true, e.target); e.target.dispatchEvent(a); a = null; return false; }, nm = true, sp = { x: 0, y: 0, }, ep = { x: 0, y: 0, }, touch = { touchstart: function (e) { sp = { x: e.touches[0].pageX, y: e.touches[0].pageY, }; }, touchmove: function (e) { nm = false; ep = { x: e.touches[0].pageX, y: e.touches[0].pageY, }; }, touchend: function (e) { if (nm) { ce(e, "fc"); } else { var x = ep.x - sp.x, xr = Math.abs(x), y = ep.y - sp.y, yr = Math.abs(y); if (Math.max(xr, yr) > 20) { ce(e, xr > yr ? (x < 0 ? "swl" : "swr") : y < 0 ? "swu" : "swd"); } } nm = true; }, touchcancel: function (e) { nm = false; }, }; for (var a in touch) { d.addEventListener(a, touch[a], false); } })(document); //EXAMPLE OF USE // var h = function (e) { // console.log(e.type, e); // }; //document.body.addEventListener("fc", h, false); // 0-50ms vs 500ms with normal click, fast click //document.body.addEventListener("swl", h, false); // swipe left //document.body.addEventListener("swr", h, false); // swipe right //document.body.addEventListener("swu", h, false); // swipe up //document.body.addEventListener("swd", h, false); // swipe down function swipe(e) { if (e.type === "swl") { // 슬라이드 오른쪽 이동 $("#myCarousel a.right").trigger("click"); } else if (e.type === "swr") { // 슬라이드 왼쪽 이동 $("#myCarousel a.left").trigger("click"); } } document.getElementById("myCarousel").addEventListener("swl", swipe, false); // swipe left document.getElementById("myCarousel").addEventListener("swr", swipe, false); // swipe left };