Last active
December 18, 2015 22:39
-
-
Save madeinfree/5855928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*******************************************************************************/ | |
/* | |
* Get Touch Event For Android | |
* record 4 coordinate | |
* 1. Touch_old_x -> touchstart x | |
* 2. Touch_old_y -> touchstart y | |
* 3. Touch_new_x -> touchmove x | |
* 4. Touch_new_x -> touchmove y | |
*/ | |
var Touch_old_x = 0, | |
Touch_old_y = 0, | |
Touch_new_x = 0, | |
Touch_new_y = 0; | |
/* | |
* Performance Optimization Touchmove event | |
* Add the setInterval to lock the move | |
* If touch move then lock the move event until touchend | |
*/ | |
var Touch_moved = false, | |
Touch_move_t; | |
document.addEventListener('touchstart', Touch_start_record, true); | |
document.addEventListener('touchmove', Touch_move, true); | |
document.addEventListener('touchend', Touch_clear, true); | |
function Touch_start_record(event) { | |
var e = event || window.event; | |
e.preventDefault(); | |
var touch_old = e.touches[0]; | |
Touch_old_x = touch_old.pageX; | |
Touch_old_y = touch_old.pageY; | |
} | |
function Touch_move(event) { | |
if(!Touch_moved) { | |
var e = event || window.event; | |
e.preventDefault(); | |
var touch_new = e.touches[0]; | |
Touch_new_x = touch_new.pageX; | |
Touch_new_y = touch_new.pageY; | |
if(Touch_new_x - Touch_old_x > 0) { | |
Touch_moved = true; | |
touch_left = 'left'; | |
oCon_m_act.textContent = '拖動狀態: ' + '手指移動「向右」'; | |
Touch_move_t = setInterval("Getround.fn.auto(touch_left)", 29.8); | |
} | |
if(Touch_new_x - Touch_old_x < 0) { | |
Touch_moved = true; | |
touch_right = 'right'; | |
oCon_m_act.textContent = '拖動狀態: ' + '手指移動「向左」'; | |
Touch_move_t = setInterval("Getround.fn.auto(touch_right)", 29.8); | |
} | |
} | |
} | |
function Touch_clear(event) { | |
Touch_moved = false; | |
clearInterval(Touch_move_t); | |
UpdateControlerTools(); | |
} | |
/*******************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment