标签:sem false jquery add int on() end cli splay
PC 端拖拽
function drag() {
var _move = false;
var _x, _y;
$(".drag").click(function() {
console.log($(".drag>g").css("display"));
}).mousedown(function(e) {
_move = true;
_x = e.pageX - parseInt($(".drag").css("left"));
_y = e.pageY - parseInt($(".drag").css("top"));
});
$(document).mousemove(function(e) {
if(_move) {
var x = e.pageX - _x;
var y = e.pageY - _y;
$(".drag").css({
top: y,
left: x
});
}
}).mouseup(function() {
_move = false;
});
}
手机 端拖拽
function drag(){
var _move=false;
var _x,_y;
var drag = document.getElementById(‘drag‘);
drag.addEventListener("touchstart",function(e){
var touch = event.targetTouches[0];
console.log(touch);
_move=true;
_x=touch.pageX-parseInt($("#drag").css("left"));
_y=touch.pageY-parseInt($("#drag").css("top"));
});
document.addEventListener("touchmove",function(e){
var touch = event.targetTouches[0];
if(_move){
var x=touch.pageX-_x;
var y=touch.pageY-_y;
$("#drag").css({top:y,left:x});
}
})
document.addEventListener("touchend",function(e){
_move=false;
});
}
jQuery拖拽
标签:sem false jquery add int on() end cli splay
原文地址:http://www.cnblogs.com/wzy1569178479/p/7341315.html