鼠标拖动选择不适用于触摸设备。我该如何解决这个问题。请检查我的 fiddle
$(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;
});
});
最佳答案
给元素附加触摸事件,例如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");
}
});
关于javascript - 鼠标拖动选择不适用于触摸设备。我怎样才能让它成为可能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33934591/