首页 新闻 赞助 找找看

实现div拖动效果,PC端成立,移动端时 touchmove事件中 moveX得到的为什么是一个恒定不变的值

0
悬赏园豆:5 [已关闭问题] 关闭于 2017-04-24 13:46

html页面:

<div class="line J_line animate" id="line">
  <div class="dash J_dash" id="dash"></div>
</div>

<script>
$(function(){
  function linemove(){
    var linestop=true; //开关
    $("#dash").on("mousedown touchstart",function(event){
    if(linestop){
      var e=event || window.event;
      var touch=event.touches?event.touches[0]:event;
      var startLeft=$("#line").css("left");
      var startX=e.pageX || touch.pageX;
      //阻止页面的滑动默认事件
      document.addEventListener("touchmove",function(){
        e.preventDefault();
      },false);
               $(".se3_main").on("mousemove touchmove",function(){
        var moveX=e.pageX || touch.pageX;
        console.log(touch.pageX);
        var moveLeft=parseFloat(startLeft)-(parseFloat(startX)-parseFloat(moveX));
        moveLeft=moveLeft<-10?-10:moveLeft>$(".pic4K").width()+10?  

        $(".pic4K").width()+10:moveLeft;
        $("#line").css("left",moveLeft+"px");
        $("#pic2K").width(moveLeft+"px");
  });
    $(".se3_main").on("mouseup touchend",function(){
      $(".se3_main").off("mousemove touchend");
    });

    }
  });
}
linemove();

});

</script>

忻韵的主页 忻韵 | 初学一级 | 园豆:184
提问于:2017-04-24 11:36
< >
分享
所有回答(1)
0

忘记传入event了

忻韵 | 园豆:184 (初学一级) | 2017-04-24 13:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册