일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- gson
- 다윈스트리밍서버
- 하스스톤
- bluestack
- 세나
- 모바일게임
- 윈도우10
- 간접표현식
- WiFi
- WebtoB
- 클래시 로얄
- Sculpt Erogonomic Desktop
- Http Live Streaming Server
- Windows 10
- ubuntu
- IT
- IT 인코딩 encoding
- 윈도우 10
- JEUS6.0
- 붕괴3
- 간접 표현식
- HTML
- jQuery
- 처비
- Clash Royale
- 세븐나이츠
- 다윈 스트리밍 서버
- 초대장
- VBA
- JEUS
Archives
- Today
- Total
공책
jQuery swipe 직접 구현하기 본문
탭 전환을 터치이벤트나 마우스클릭 이벤트로 스와이프 되게 구현한 것입니다.
css 부분
각 div를 가로로 배열합니다.
div.tab_right { left: 100%; } div.tab_left, div.tab_right { width: 100%; position: absolute; }스크립트
페이지가 스와이프 되는 애니메이션 부분입니다.
단순하게 생각하여 두페이지를 나열하고 각페이지의 left값을 조정하여 좌우로 이동시키고
화면 밖으로 나간 div은 숨김처리하여 가로 스크롤이 나오지 않게 합니다.
$(".tab_left").show().animate({ left : '0' }); $(".tab_right").animate({ left : '100%' }, function(){ this.style.display = 'none'; }); $(".tab_left").animate({ left : '-100%' }, function(){ this.style.display = 'none'; }); $(".tab_right").show().animate({ left : '0' });페이지의 이벤트를 체크하는 부분
클릭이나 터치된 부분의 좌표로부터 이동한 좌표를 계산하여 좌/우 를 판별합니다.
다만 수직 스크롤시 약간 이동하는 부분이 있기 때문에 감도로 상수값을 줬습니다.
var startX = 0; var endX = 0; var sensitive = 90; $(document).bind('touchstart mousedown', function(e) { e.preventDefault(); // 이벤트취소 if (e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel') { var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; startX = touch.pageX; } else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover' || e.type == 'mouseout' || e.type == 'mouseenter' || e.type == 'mouseleave') { startX = e.pageX; } }); $(document).bind('touchend mouseup', function(e) { e.preventDefault(); // 이벤트취소 if (e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel') { var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; endX = touch.pageX; } else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover' || e.type == 'mouseout' || e.type == 'mouseenter' || e.type == 'mouseleave') { endX = e.pageX; } if(startX + sensitive < endX){ swipe("left"); } else if(startX > endX + sensitive) { swipe("right"); } });
'웹 개발 > JSP' 카테고리의 다른 글
include 된 JSP 페이지 한글 깨짐 문제 발생 시 (0) | 2013.10.24 |
---|
Comments