Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make html text box draggable and resizable using jQuery UI plugins?

Using jquery ui draggable plugin, I've made html text box draggable in this way:

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $("#Text1").draggable({
            containment: "parent",
            cancel: null
        });
    });
</script>

<form id="form1" runat="server">
<div>

    <div id="dialog" title="Dialog Box" style="border: solid 1px black;">
        <input id="Text1" type="text" style="width: 200px; height: 20px;" value="Text1" />
    </div>

</div>
</form>

But, how to make it resizable using jQuery as well?

Thank you in advance.

Goran

like image 675
tesicg Avatar asked May 24 '12 07:05

tesicg


People also ask

How do you make something draggable in jQuery?

jQuery UI draggable() method is used to make any DOM element draggable. Once the element is made draggable, you can move it by clicking on it with the mouse and drag it anywhere within the viewport.

How do you make a draggable element in HTML?

To make an object draggable set draggable=true on that element. Just about anything can be drag-enabled: images, files, links, files, or any markup on your page.

How does jQuery ui draggable work?

Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port. If the value of this option is set to false, it will prevent the DOM elements to be dragged .

Why draggable is not working?

Check whether your draggable object is already loaded in the viewport. If it is not, it won't work properly. JUST AFTER the draggable object to be absolutely sure that everything is loaded at the correct time. When you'll be sure everything is ok, then you'll be able to refactor.


2 Answers

Here is the DEMO to make the HTML textbox resizable and draggable using jquery-ui

HTML:

<div id="container" class="ui-widget-content">
<h3 class="ui-widget-header">Containment</h3>
<span id="draggable">*  
<input type="text "id="resizable" class="ui-state-active" value="This is input box">
</span>
</div>

JS:

$(function() {
     $( "#resizable" ).resizable({
containment: "#container"
});
     $( "#draggable" ).draggable({containment: "#container"});
});
like image 153
Rahul Gupta Avatar answered Oct 13 '22 01:10

Rahul Gupta


By using jQuery UI.
HTML FILE
<input type="text" id="resizable" />
JavaScript File reference all needed jQuery files in script tag i.e

<script src="*all needed .js files*"></script>

<script>
    $(function() {      
    $( "#resizable" ).resizable();
});
</script>

by the way why u need to make textbox resizable

like image 37
Vivek Avatar answered Oct 13 '22 00:10

Vivek