Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent text/element selection with cursor drag

I made a paging control and I noticed that while clicking on the buttons it is very easy to accidentally select the individual images and text. Is it possible to prevent this?

To clarify selecting I mean highlighting with the mouse. (Try dragging your mouse from one side of the screen to the other.)

If you try to highlight the text/controls in this grid it can't be selected. How is that done? Link

like image 908
The Muffin Man Avatar asked Mar 25 '11 07:03

The Muffin Man


People also ask

How do I turn off text selection?

You can use the user-select property to disable text selection of an element. In web browsers, if you double-click on some text it will be selected/highlighted. This property can be used to prevent this.

How do I turn off highlighting?

To disable text selection highlighting in Google Chrome browser using CSS just set -user-select CSS property to none. And no prefix is required for Google Chrome and Opera Browsers.


1 Answers

dragging and selecting both initialize on a mouse down event and update on subsequent mouse moves. When you handle the events to begin dragging, or to follow the mouse, cancel the event's bubbling and override the default browser return:

something like this in your begin dragging mousedown and move handlers-

e=e || window.event; pauseEvent(e); 
function pauseEvent(e){     if(e.stopPropagation) e.stopPropagation();     if(e.preventDefault) e.preventDefault();     e.cancelBubble=true;     e.returnValue=false;     return false; } 
like image 92
kennebec Avatar answered Sep 28 '22 17:09

kennebec