//菜单栏滑动
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);
}
});
}
菜单栏滑动交互实现
本文介绍了一种使用JavaScript实现的菜单栏滑动交互方法,通过监听touchstart、touchmove和touchend事件来控制菜单栏元素的位置变化,实现响应式的左右滑动效果。

871

被折叠的 条评论
为什么被折叠?



