代码描述:zepto判断 左右滑动。zepto判断左右滑动
分享一段代码实例,它利用zepto实现了判断左右滑动的功能。 代码实例如下:
<script> var startPosition, endPosition, deltaX, deltaY, moveLength; $(".content").bind('touchstart', function(e) { var touch = e.touches[0]; startPosition = { x: touch.pageX, y: touch.pageY } }).bind('touchmove', function(e) { var touch = e.touches[0]; endPosition = { x: touch.pageX, y: touch.pageY }; deltaX = endPosition.x - startPosition.x; deltaY = endPosition.y - startPosition.y; moveLength = Math.sqrt(Math.pow(Math.abs(deltaX), 2) + Math.pow(Math.abs(deltaY), 2)); }).bind('touchend', function(e) { if (deltaX < 0) { // 向左划动 console.log("向左划动"); } else if (deltaX > 0) { // 向右划动 console.log("向右划动"); } }); </script>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能