<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css"/>
Code language: HTML, XML (xml)
Note that we have imported jquery and jquery-ui library. Also, to use Resizable we must import jquery-ui.css file. This stylesheet will be used by resizable to add resize corner and other internal styles. <div id="resizeDiv"></div>
Code language: HTML, XML (xml)
Now just add following jQuery code in your document. $('#resizeDiv')
.draggable()
.resizable();
Code language: JavaScript (javascript)
The beauty of jQuery is that we can simply chain the function calling. First we called .draggable() function that makes the DIV draggable and then we called resizable(). You may want to define callback functions on start/stop/resize events. To do so we simply define: $('#resizeDiv')
.resizable({
start: function(e, ui) {
alert('resizing started');
},
resize: function(e, ui) {
},
stop: function(e, ui) {
alert('resizing stopped');
}
});
Code language: JavaScript (javascript)
Note that the callback function gets two arguments. First is event object and next is ui. The ui object has the following fields: Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…
Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…
Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…
1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…
GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…
1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…
View Comments
awesome code.... :)
Thanks Gaurav...
Thanks, very useful tutorial.
This is indeed great stuff!
One question: I am trying to add multiple divs on a page that can be dragged, dropped and resized, but it appears that only one div can be activated at a time? I am trying to reactivate a given div on a mouseover, but the resizing doesn't seem to be kicking back in. Is there some way to un-initialize the non-active divs?
Thanks!
There is some bug within jQuery resizable.
If you specify aspectRatio:true and resize the target, the target's aspect ratio is not well respected. i.e. If you resize the target back and forth quickly for a few times, a 4x4 square div may become a 4:1 rectangular.
i have one question.....
we are developing a website. we need to include a non interactive slider in that. how to design a slider using JQuery Javascript?
this is really awesome tutorial
Ya, that's right
ya, very true.
This was a great tutorial. I'm using it now at work, for a website I am building for my company.
However, I've gotten stuck because the code doesn't work on Internet Explorer (not even Version 9, which is the most advanced, and supposedly the least crappy version of Explorer).
Does anyone have any idea how I can improve/edit/manage the code or the CSS/HTML so that I can do the same thing in Explorer? Any help is appreciated.
Thanks!
cant resizeable :(
help me
Nice and clean solution, I was experiencing problems with constraining both operations to a parent div - apparently I was too intrusive with changing coords in the intermediate divs...
One note: I wasn't able to access ui.size / ui.sizeOriginal from the stop event of a draggable (used a shared event handler for both drag and resize stop), so I resorted to $(event.target) and its height() / width()