[英]Javascript dragging selects text and elements around the drag area
我正在使用以下代码来允许用户垂直调整DIV元素的大小,但是当单击并拖动手柄时,就选择了页面上的文本和其他元素,就好像用户只是单击并突出显示页面上的所有内容一样。 有一种方法可以防止这种情况的发生,因为这看起来很糟糕? 这正在与Prototype.js一起使用。
function DragCorner(container, handle) {
var container = $(container);
var handle = $(handle);
// Add property to container to store position variables
container.moveposition = {y:0};
function moveListener(event) {
// Calculate how far the mouse moved
var moved = { y:(container.moveposition.y - event.pointerY()) };
// Reset container's x/y utility property
container.moveposition = {y:event.pointerY()};
// Update container's size
var size = container.getDimensions();
container.setStyle({height: size.height + moved.y + 'px'});
}
// Listen for 'mouse down' on handle to start the move listener
handle.observe('mousedown', function(event) {
// Set starting x/y
container.moveposition = {y:event.pointerY()};
// Start listening for mouse move on body
Event.observe(document.body,'mousemove',moveListener);
});
// Listen for 'mouse up' to cancel 'move' listener
Event.observe(document.body,'mouseup', function(event) {
Event.stopObserving(document.body,'mousemove',moveListener);
console.log('stop listening');
});
}
在前面的问题和答案之后,添加一个小手柄元素,并将其作为唯一可以选择和拖动的元素。 另外我猜你把div的位置设置为relative
位置,把手柄的位置设置为absolute
位置。 对??
在DIV中添加以下内容可解决此问题:
onselectstart="return false;"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.