码迷,mamicode.com
首页 > 移动开发 > 详细

jquery制作移动端菜单栏左右滑动

时间:2017-03-22 16:39:59      阅读:682      评论:0      收藏:0      [点我收藏+]

标签:bind   移动端   start   move   end   his   mat   original   css   

//菜单栏滑动
function move_scollX(){
var startPosition, endPosition, distanceX,distanceY;
$(".left").bind(‘touchstart‘, function(e){ 
  var touch = e.originalEvent.changedTouches[0]; //移动端
  startPosition = {
    x: touch.pageX,
    y:touch.pageY
  }
}) .bind(‘touchmove‘, function(e){

  var touch = e.originalEvent.changedTouches[0]; //移动端
  endPosition = {
    x: touch.pageX,

    y:touch.pageY

}; 

distanceX = endPosition.x - startPosition.x;

distanceY = endPosition.Y - startPosition.Y; 
if(distanceX < 0) { // 向左移动
  $(this).css({"left":distanceX});
} else if (distanceX > 0) { // 向右移动
  $(this).css({"left":distance});
}
}
}
}).bind(‘touchend‘, function(e){ //放开事件
  $(this).animate({"left":-width},100);
}
});
}

jquery制作移动端菜单栏左右滑动

标签:bind   移动端   start   move   end   his   mat   original   css   

原文地址:http://www.cnblogs.com/weiman/p/6600380.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!