我目前正在开发一个iPhone网页,其中包含一个DIV元素,用户可以触摸并拖动。此外,当用户将元素拖动到设备屏幕的顶部或底部时,我想自动向上或向下滚动页面。
我遇到的问题是尝试确定在onTouchMove事件中获取的坐标与用户手指到达设备视口顶部或底部相对应的可靠公式。我的当前公式似乎很繁琐,我觉得可能有更简单的方法来解决这个问题。
我目前用于确定触摸事件是否已到达屏幕底部的公式为:
我遇到的问题是尝试确定在onTouchMove事件中获取的坐标与用户手指到达设备视口顶部或底部相对应的可靠公式。我的当前公式似乎很繁琐,我觉得可能有更简单的方法来解决这个问题。
我目前用于确定触摸事件是否已到达屏幕底部的公式为:
function onTouchMoveHandler(e)
{
var orientation=parent.window.orientation;
var landscape=(orientation==0 || orientation==180)?true:false;
var touchoffsety=(!landscape?screen.height - (screen.height - screen.availHeight):screen.width - (screen.width - screen.availWidth)) - e.touches[0].screenY + (window.pageYOffset * .8);
if(touchoffsety < 40) alert('finger is heading off the bottom of the screen');
}
我已经在诸如window、document、body、e.touches等对象上进行了一些Javascript反射,以寻找一个始终相加等于屏幕顶部或底部的数字集,但没有可靠的成功。希望能够得到关于此问题的帮助。