jQuery & CSS: simulate windows (part 2)
In my last post I explained how to simulate a window with show/hide and close buttons. Now I'm going to show you how to complete the work adding drag and resize.
Remember our example?
Yeah! That's it. Now let's see how to make the window draggable and resizable with jQuery UI.
As a start you should go and see my last post jQuery & CSS: simulate windows because we are going to change that code and probably you need to know what we've already achieved.
Let's start from the top of our page and see what to change.
Now your window is resizable and draggable!
Remember our example?
Yeah! That's it. Now let's see how to make the window draggable and resizable with jQuery UI.
As a start you should go and see my last post jQuery & CSS: simulate windows because we are going to change that code and probably you need to know what we've already achieved.
Let's start from the top of our page and see what to change.
Adding the correct library
First of all we need to add a new library (jQuery UI) and the related stylesheet:
Again, remember to change the path to the library according to yours.Add the function
Then we change our jQuery code, adding the highlighted part of the following snippet:
The highlighted part will make our window draggable and resizable. As you have noticed, we added a new container called "wrap" for the drag function. For the resize effect, we used the "alsoResize" option because we need to resize both the "content" div and the "bar" div.The styles
We need to change the styles as well. To make things easier, replace all your style with the following:
Basically we just added two things to the "bar" div style: min-height and max-height. That is because we don't want the bar to shrink "too much" when the window is resized.The divs
The divs do not change much: just add the hightlighted part:
The content of your window goes here. Please notice that it flows correctly.
Very easy, isn't it?Now your window is resizable and draggable!