How to make textarea draggable? (i.e. block text selection, but allow cursor positioning)

I have a text field that I configured to drag and drop, but it isn’t ... The browsers I tested (FireFox 3 and Safari 3 on OS X) believe that I am trying to select text inside a text field (even if they are not).

I would like to allow a click inside the text box to place the cursor for editing, but the drag and drop movement should be handled by jquery-ui.

An html example that does not do what I want below ...

    <html>
    <head>
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.7.custom.min.js"></script>
     <script type="text/javascript">
    $(function(){
            $("div").draggable();
            $("textarea").draggable();
    });
    </script>
    <style type="text/css">
    div {
            position:               fixed;
            top:                    100px;
            left:                   100px;
            width:                  100px;
            height:                 100px;
            background-color:       blue;
    }
    textarea {
            width:                  80%;
            height:                 80%;
            background-color:       yellow;
            resize:                 none;
    }
    </style>        
    </head>
    <body>
    <div>
    <textarea>Pirates spotted!</textarea>
    </div>
    </body>
    </html>
+3
source share
1 answer

You can use the jQuery-UI dialog box library and put the text area inside. You can make the dialog draggable.

+1

Source: https://habr.com/ru/post/1704677/


All Articles