Windows runtime 如何确定MSGestureChange事件中的当前指针x位置?

Windows runtime 如何确定MSGestureChange事件中的当前指针x位置?,windows-runtime,winjs,Windows Runtime,Winjs,这听起来像是重复的,但请听我说,因为我需要一个具体的答案 我创建的UI需要在用户拖动时进行可视化更改,而不是在完成时。我发现了如何根据数组中的选定项向左偏移位置来确定我们是向左移动还是向右移动,以及如何在从该位置向右移动时确定指针的位置,并且能够提供良好的视觉反馈。现在我也知道了如何确定是否从数组中的选定项向左偏移位置向左移动,如何确定指针向左移动的距离?我已经为此挣扎了好几个小时了 以下是我到目前为止的总结: var ActiveElement = null; function init()

这听起来像是重复的,但请听我说,因为我需要一个具体的答案

我创建的UI需要在用户拖动时进行可视化更改,而不是在完成时。我发现了如何根据数组中的选定项向左偏移位置来确定我们是向左移动还是向右移动,以及如何在从该位置向右移动时确定指针的位置,并且能够提供良好的视觉反馈。现在我也知道了如何确定是否从数组中的选定项向左偏移位置向左移动,如何确定指针向左移动的距离?我已经为此挣扎了好几个小时了

以下是我到目前为止的总结:

var ActiveElement = null;

function init() {
    touchElement.msg = new MSGesture();
    touchElement.msg.target = touchElement;
    touchElement.addEventListener("MSGestureStart", te_gs, false);
    touchElement.addEventListener("MSGestureChange", te_gc, false);
    touchElement.addEventListener("MSGestureEnd", te_ge, false);
    touchElement.addEventListener("MSInertiaStart", te_is, false);
    touchElement.addEventListener("MSPointerDown", te_pd, false);
    touchElement.addEventListener("MSPointerUp", te_pu, false);
    touchElement.addEventListener("MSGestureTap", te_click, false);
};

//************************************************************************************************************************
// POINTER DOWN
//************************************************************************************************************************
function te_pd(e) {
    //get activeel pos
    ActiveElement.pos = getElPos(ActiveElement);
    var touchE = e.currentTarget;
    touchE.msg.addPointer(e.pointerId);
}

//************************************************************************************************************************
// GESTURE START
//************************************************************************************************************************
function te_gs(e) {
    // set touchElement to the widget
    var touchE = e.currentTarget;

    // track the location from the start
    touchE.diffx = ActiveElement.offsetLeft - e.clientX;
}

//************************************************************************************************************************
// GESTURE CHANGE
//************************************************************************************************************************
function te_gc(e) {
    var touchE = e.currentTarget;

    var activeElementLeftEdge = listArray[ActiveElement.pos].offsetLeft - listArray[ActiveElement.pos - 1].offsetLeft;

    var dragRight = e.translationX > ActiveElement.offsetLeft - e.clientX;

    var dragLeft = e.translationX < ActiveElement.offsetLeft - e.clientX;

    if (dragRight) {
        // I'm doing stuff to the right here where activeElementLeftEdge helps me determine the current location of the pointer going to the right
        // my problem is that I don't know how to determine the equivalent when moving left
        if (activeElementLeftEdge > listArray[ActiveElement.pos - 1].offsetLeft * 0) {
            // show state
        } else if (activeElementLeftEdge < 100) {
            // hide state
        }

        if (activeElementLeftEdge > 200) {
            // show next state
        } else if (activeElementLeftEdge < 200) {
            // hide state
        }
    }

    if (dragLeft) {
        // How do I determine the x position of the pointer here? 
    }
}

//************************************************************************************************************************
// GESTURE END
//************************************************************************************************************************
function te_ge(e) {

}

//************************************************************************************************************************
// POINTER UP
//************************************************************************************************************************
function te_pu(e) {

}

//************************************************************************************************************************
// INERTIA STARTING
//************************************************************************************************************************
function te_is(e) {

}

//************************************************************************************************************************
// CLICKED
//************************************************************************************************************************
function te_click(e) {

}

//************************************************************************************************************************
//returns the element position in the listArray
//************************************************************************************************************************
function getElPos(element) {
    //loop through the array
    for (i = 0; i < listArray.length; i++) {
        if (listArray[i].id == element.id) {
            return (i);
        }
    }
}
var-ActiveElement=null;
函数init(){
touchElement.msg=new-mspirture();
touchElement.msg.target=touchElement;
touchElement.addEventListener(“MSGestureStart”,te_gs,false);
touchElement.addEventListener(“MSGestureChange”,te_gc,false);
touchElement.addEventListener(“MSGestureEnd”,te_ge,false);
addEventListener(“MSInertiaStart”,te_is,false);
touchElement.addEventListener(“MSPointerDown”,te_pd,false);
touchElement.addEventListener(“MSPointerUp”,te_pu,false);
touchElement.addEventListener(“MSGestureTap”,te_click,false);
};
//************************************************************************************************************************
//向下指针
//************************************************************************************************************************
功能te_pd(e){
//获取activeel pos
ActiveElement.pos=getElPos(ActiveElement);
var touchE=e.currentTarget;
touchE.msg.addPointer(e.pointerId);
}
//************************************************************************************************************************
//手势开始
//************************************************************************************************************************
功能测试(e){
//将touchElement设置为小部件
var touchE=e.currentTarget;
//从一开始就跟踪位置
touchE.diffx=ActiveElement.offsetLeft-e.clientX;
}
//************************************************************************************************************************
//手势变化
//************************************************************************************************************************
函数te_gc(e){
var touchE=e.currentTarget;
var activeElementLeftEdge=listArray[ActiveElement.pos].offsetLeft-listArray[ActiveElement.pos-1].offsetLeft;
var dragRight=e.translationX>ActiveElement.offsetLeft-e.clientX;
var dragLeft=e.translationXlistArray[ActiveElement.pos-1].offsetLeft*0){
//显示状态
}else if(activeElementLeftEdge<100){
//隐藏状态
}
如果(activeElementLeftEdge>200){
//显示下一状态
}else if(activeElementLeftEdge<200){
//隐藏状态
}
}
如果(拖航){
//如何确定指针的x位置?
}
}
//************************************************************************************************************************
//手势结束
//************************************************************************************************************************
职能部门(e){
}
//************************************************************************************************************************
//指向上
//************************************************************************************************************************
特鲁普(e)职能{
}
//************************************************************************************************************************
//惯性起动
//************************************************************************************************************************
函数te_is(e){
}
//************************************************************************************************************************
//点击
//************************************************************************************************************************
功能TEU点击(e){
}
//************************************************************************************************************************
//返回listArray中的元素位置
//************************************************************************************************************************
函数getElPos(元素){
//在数组中循环
对于(i=0;i
会有帮助吗?现在还不太清楚您在寻找什么?我建议您研究一下手势识别器类。它是用来帮助你做你想做的事情的。以下是一篇可能对您有所帮助的文章: