Get selection event + selection movement - Jquery

3

I would like to know how to get the event with Jquery from text selection + drag.

An example of what I'm saying is to select a text and with the left mouse button pressed, move the text sideways.

How do I get this event? Let's say: if certain text is selected in the div and if I click on it and move. How would you find out that this event occurred? Well, it's not just selecting, it's clicking and moving the selection.

By analyzing, I found this example where I am prevented from selecting the div text with drag. I know it's possible to do with css, but in my situation there are inputs, so maybe someone wants to select.

link

How did they prevent you from selecting the text in the example above?

    
asked by anonymous 05.05.2016 / 23:49

1 answer

2

Selecting text and clicking and dragging use similar mouse events soon depends a little on other factors (interface, html, etc.) to develop something 100% functional for you. But below is a possibility. With this example you can adapt the same to your needs.

link

document.onselectionchange = function() {
  var selObj = window.getSelection();
  var selRange = selObj.toString();
  console.log(selRange);
  
  document.querySelector('.selection').innerHTML = selRange;

};

$(".selection").draggable({
  cursor: "crosshair"
});
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<div class="element">
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Unde blanditiis, accusamus cum nihil laboriosam magnam animi sed provident nisi a debitis numquam sequi sit rerum dignissimos? Eveniet tempore consequuntur, aperiam.
</div>
<br>
<div class="selection">
  
</div>

I hope I have helped: D

    
06.05.2016 / 21:08