找出deltaY距离?
Find out the deltaY distance?
如何找到触摸中心的距离?
比如我们触摸,如果我们往上拉,我们得到1 2 3。如果我们往下拉,我们得到-1 -2 -3。
我知道可以使用保存的位置(开始触摸)来完成。但是我自己想不通。谢谢!
// touchstart
window.addEventListener('touchmove', touchmove);
var deltaY;
function touchmove(e) {
deltaY = e.touches[0].clientY;
console.log(deltaY);
}
您可以创建 2 个事件监听器,一个用于捕获开始位置,另一个用于捕获移动事件:
document.body.addEventListener('touchmove', touchmove);
document.body.addEventListener('touchstart', touchstart);
var startX, startY;
function touchstart(e)
{
startX = e.touches[0].clientX;
startY = e.touches[0].clientY;
}
function touchmove(e)
{
var deltaX = e.touches[0].clientX - startX,
deltaY = e.touches[0].clientY - startY;
console.log('Delta x,y',deltaX, deltaY);
}
如何找到触摸中心的距离?
比如我们触摸,如果我们往上拉,我们得到1 2 3。如果我们往下拉,我们得到-1 -2 -3。
我知道可以使用保存的位置(开始触摸)来完成。但是我自己想不通。谢谢!
// touchstart
window.addEventListener('touchmove', touchmove);
var deltaY;
function touchmove(e) {
deltaY = e.touches[0].clientY;
console.log(deltaY);
}
您可以创建 2 个事件监听器,一个用于捕获开始位置,另一个用于捕获移动事件:
document.body.addEventListener('touchmove', touchmove);
document.body.addEventListener('touchstart', touchstart);
var startX, startY;
function touchstart(e)
{
startX = e.touches[0].clientX;
startY = e.touches[0].clientY;
}
function touchmove(e)
{
var deltaX = e.touches[0].clientX - startX,
deltaY = e.touches[0].clientY - startY;
console.log('Delta x,y',deltaX, deltaY);
}