jquery - 相当于移动设备的 mousemove

标签 jquery mousemove

想知道是否有适用于移动设备的 mousemove 的等效项,例如 touchmove 或 touchdrag 等。

我在容器中有一个图像,可以使用鼠标移动在悬停时平移该图像。有没有办法也可以针对移动设备进行优化?

function MouseMove(e){
        var mouseCoordsX=(e.pageX - $imagePan.offset().left);
        var mouseCoordsY=(e.pageY - $imagePan.offset().top);
        var mousePercentX=mouseCoordsX/containerWidth;
        var mousePercentY=mouseCoordsY/containerHeight;
        var destX=-(((totalContentW-(containerWidth))-containerWidth)*(mousePercentX));
        var destY=-(((totalContentH-(containerHeight))-containerHeight)*(mousePercentY));
        var thePosA=mouseCoordsX-destX;
        var thePosB=destX-mouseCoordsX;
        var thePosC=mouseCoordsY-destY;
        var thePosD=destY-mouseCoordsY;
        var marginL=$imagePan_panning.css("marginLeft").replace("px", "");
        var marginT=$imagePan_panning.css("marginTop").replace("px", "");
        var animSpeed=500; //ease amount
        var easeType="easeOutCirc";
        if(mouseCoordsX>destX || mouseCoordsY>destY){
            //$imagePan_container.css("left",-thePosA-marginL); $imagePan_container.css("top",-thePosC-marginT); //without easing
            $imagePan_container.stop().animate({left: -thePosA-marginL, top: -thePosC-marginT}, animSpeed,easeType); //with easing
        } else if(mouseCoordsX<destX || mouseCoordsY<destY){
            //$imagePan_container.css("left",thePosB-marginL); $imagePan_container.css("top",thePosD-marginT); //without easing
            $imagePan_container.stop().animate({left: thePosB-marginL, top: thePosD-marginT}, animSpeed,easeType); //with easing
        } else {
            $imagePan_container.stop();
        }
    }

    $imagePan_panning.css("margin-left",($imagePan.width()-$imagePan_panning.width())/2).css("margin-top",($imagePan.height()-$imagePan_panning.height())/2);

    $imagePan.bind("mousemove", function(event){
        MouseMove(event);


    });

最佳答案

是的,你也猜对了。

这是touchmoveReference here

关于jquery - 相当于移动设备的 mousemove,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19927665/

相关文章:

javascript - 为什么 "$(this)"在以下示例中不起作用

javascript - 淡入淡出效果影响我的输出

python - 跟踪屏幕上的鼠标移动(形状) - Python

c# - 在运行时移动控制

javascript - 如何获取相对于父 div 的鼠标坐标? JavaScript

javascript - 如何测试CSS文件是否链接到head中

javascript - 使用 jquery 禁用特定条件的下拉菜单

javascript点击事件不触发 Action

javascript - 在 mousemove kineticJS 上更改半径

jquery - 通过 mousemove 获取元素