我创建了一个使div可左右拖动的代码。它可以在PC上使用,但不能在android上使用。我尝试添加touchstart,但这似乎无法解决。谁能看到什么地方不对?
预先感谢
<!DOCTYPE HTML>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="crossorigin="anonymous"></script>
</head>
<style>
#allhold{
background-color:yellow;
padding:20px;
margin:20px;
overflow:auto;
}
.dragme{
width:70px;
height:50px;
background-color:blue;
margin:5px;
position:relative;
float:left;
z-index:1;
}</style>
<script>
$(document).ready(function(){
$("#dragtest").on("mousemove touchstart", function(e) {
if (e.which == 1) {
var halfwidth=($(this).width()/2);
var newleft = e.pageX -halfwidth;
$("#testdiv").html(e.pageX + " / " + newleft);
$(this).css({"position":"absolute", "left":newleft,"background-color":"azure"});
}
});
});
</script>
<body>
<div id="allhold">
<div id="dragtest" class="dragme" >draggable 3</div>
</div>
<div id="testdiv"></div>
</body>
</html>