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>
忘记传入event了