kan*_*D.S 5 html javascript css jquery
鼠标拖动选择不适用于触摸设备。我该如何解决这个问题。请检查我的小提琴
$(function () {
var isMouseDown = false;
$("#our_table td")
.mousedown(function () {
isMouseDown = true;
$(this).toggleClass("highlighted");
return false; // prevent text selection
})
.mouseover(function () {
if (isMouseDown) {
$(this).toggleClass("highlighted");
}
});
$(document)
.mouseup(function () {
isMouseDown = false;
});
});
Run Code Online (Sandbox Code Playgroud)
小智 0
将触摸事件(例如 touchstart、touchend、touchmove)附加到元素上。例如,
$("#our_table td")
.touchstart(function () {
isMouseDown = true;
$(this).toggleClass("highlighted");
return false; // prevent text selection
})
.touchmove(function () {
if (isMouseDown) {
$(this).toggleClass("highlighted");
}
});
Run Code Online (Sandbox Code Playgroud)