View Full Version : mousedown event handlers
mjabon
02-22-2008, 08:13 AM
Hello. I have implemented a simple drag and drop senario, however, when I drag the item the text underneath will get highlighted as if I were selecting text. Right now when someone clicks on my movable "DVD player" (the object that is dragged and dropped) I just register my function processMouseDown(event) and then I have two other methods I register called processMouseMove and processMouseUp that takes care of the moving and dropping. Does anyone know how to turn off the automatic text selecting?
mjlorbet
02-22-2008, 09:14 AM
setCapture() will capture the mouse on the object you're dragging (JS) preventing the stuff from getting higlighted, releaseCapture() on mouse up. This is IE specific mind you, so check the mozilla documentation for the FF implementation.
You may use this piece of code:
<script type="text/javascript">
function disableSelection(target){
if (typeof target.onselectstart!="undefined"){ //IE
target.onselectstart=function(){return false}
}
else if (typeof target.style.MozUserSelect!="undefined"){ //Moz
target.style.MozUserSelect="none";
}
else{ // other
target.onmousedown=function(){return false}
target.style.cursor = "default";
}
}
onload=function(){
disableSelection(document.documentElement)
}
</script>
But I guess you need to combined it some how with your drag'n'drop onmousedown event handling
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.