我正在尝试创建一个可以重新排序的项目列表。我已在移动设备上进行了设置,其中项目在长按后开始移动,然后拖动以重新定位它。
当只有少数项目存在时,它工作正常,但一旦出现足够的项目,就可以允许 div
滚动(仅包含 ul
的 div
code> 滚动,而不是整个页面),我无法再重新定位项目,因为拖动会导致滚动。
我已尝试在 touchmove
上使用 .preventDefault()
,但似乎没有效果。
基本上,我有这个:
$(document).on('touchmove mousemove', e => {
// check to make sure we're holding something
// if not, just return
e.preventDefault()
// this stops the text from being highlighted,
// but does not stop scrolling
// report the mouse/touch position to the actual move function.
})
大多数解决方案都说使用 preventDefault()
会阻止它,但事实似乎并非如此。
我在这里能做什么?
编辑:我尝试过操作 overflow
属性,但这也阻止了 div 以编程方式滚动,而这是它需要做的。
最佳答案
尝试阻止滚动:
$('div').on('scroll', function(e) {e.preventDefault()});
关于javascript - 在移动设备上拖动时禁用滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44339945/