roojs-all.js
[roojs1] / examples / resizable / basic.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
4 <title>Resizable Examples</title>
5   <link rel="stylesheet" type="text/css" href="../../cssX/roojs-all.css"/>
6     <link rel="stylesheet" type="text/css" href="../../cssX/xtheme-slate.css"/>
7
8      <script type="text/javascript" src="../../roojs-all.js"></script>   
9    <script type="text/javascript" src="../../Roo/Resizable.js"></script>
10    
11    
12 <script language="javascript" src="basic.js"></script>
13
14 <!-- Common Styles for the examples -->
15 <link rel="stylesheet" type="text/css" href="../examples.css" />
16 <style type="text/css">
17 #basic, #animated {
18     border:1px solid #c3daf9;
19     color:#1e4e8f;
20     font:bold 14px tahoma,verdana,helvetica;
21     text-align:center;
22     padding-top:20px;
23 }
24 #snap {
25     border:1px solid #c3daf9;
26     overflow:hidden;
27 }
28 #custom {
29     cursor:move;
30 }
31 #custom-rzwrap{
32     z-index: 100;
33 }
34 #custom-rzwrap .x-resizable-handle{
35     width:11px;
36     height:11px;
37     background:transparent url(../../resources/images/default/sizer/square.gif) no-repeat;
38     margin:0px;
39 }
40 #custom-rzwrap .x-resizable-handle-east, #custom-rzwrap .x-resizable-handle-west{
41     top:45%;
42 }
43 #custom-rzwrap .x-resizable-handle-north, #custom-rzwrap .x-resizable-handle-south{
44     left:45%;
45 }
46 </style>
47 </head>
48
49 <body>
50 <script type="text/javascript" src="../examples.js"></script><!-- EXAMPLES -->
51 <h1>Resizable Examples</h1>
52 <p>These examples show how to apply a floating (default) and pinned Resizable component to a standard element.</p>
53 <p>Note that the js is not minified so it is readable. See <a href="basic.js">basic.js</a> for the full source code.</p>
54
55 <p>
56     <b>Basic Example</b><br />
57     This is a basic as you get. To resize the box, position your mouse anywhere near the bottom,
58     right or border right edge of the box. This example uses the default "floating" handles.
59 </p>
60 <div id="basic">Resize Me!</div>
61 <pre class="code"><code>var basic = new Ext.Resizable('basic', {
62         width: 200,
63         height: 100,
64         minWidth:100,
65         minHeight:50
66 });</code></pre>
67 <hr>
68 <p>
69     <b>Wrapped Elements</b><br />
70
71     Some elements such as images and textareas don't allow child elements. In the past, you had
72     to wrap these elements and set up a Resizable with resize child. As of yui-ext .33 RC2, Resizable will
73     wrap the element, calculate adjustments for borders/padding and offset the handles for you. All you have to
74     do is set "wrap:true". The manual way of specifying a "resizeChild" is still supported as well.
75 </p><p>
76     <b>Pinned Handles</b><br />
77     Notice this example has the resize handles "pinned". This is done by setting "pinned:true".
78 </p><p>
79     <b>Dynamic Sizing</b><br />
80     If you don't like the proxy resizing, you can also turn on dynamic sizing. Just set "dynamic:true".
81 </p>
82 <p>
83     Here's a textarea that is wrapped, has pinned handles and has dynamic sizing turned on.
84
85 </p>
86 <textarea id="dwrapped">
87 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna. Aliquam commodo ullamcorper erat. Nullam vel justo in neque porttitor laoreet. Aenean lacus dui, consequat eu, adipiscing eget, nonummy non, nisi. Morbi nunc est, dignissim non, ornare sed, luctus eu, massa.
88 Vivamus eget quam. Vivamus tincidunt diam nec urna. Curabitur velit. Quisque dolor magna, ornare sed, elementum porta, luctus in, leo.
89 </textarea><br /><br />
90 And look how simple the code is, even my grandma could write it.
91 <pre class="code"><code>var dwrapped = new Ext.Resizable('dwrapped', {
92     wrap:true,
93     pinned:true,
94     width:450,
95     height:150,
96     minWidth:200,
97     minHeight: 50,
98     dynamic: true
99 });</code></pre>
100 <hr>
101 <p>
102 <b>Preserve Ratio</b><br />
103     For some things like images, you will probably want to preserve the ratio of width to height. Just set preserveRatio:true.
104 </p>
105 <img id="wrapped" src="sara.jpg" width="200" height="250"/>
106 <pre class="code"><code>var wrapped = new Ext.Resizable('wrapped', {
107     wrap:true,
108     pinned:true,
109     minWidth:50,
110     minHeight: 50,
111     preserveRatio: true
112 });</code></pre>
113 <hr>
114
115 <p>
116 <b>Transparent Handles</b><br />
117     If you just want the element to be resizable without any fancy handles, set transparent to true.
118 </p>
119 <img id="transparent" src="zack.jpg" width="100" height="176"/>
120 <pre class="code"><code>var transparent = new Ext.Resizable('transparent', {
121     wrap:true,
122     minWidth:50,
123     minHeight: 50,
124     preserveRatio: true,
125     transparent:true
126 });</code></pre>
127 <hr>
128 <p>
129     <b>Customizable Handles</b><br />
130     Resizable elements are resizable 8 ways. 8 way resizing for a static positioned element will cause the element to be positioned relative and taken out of the document flow. For resizing which adjusts the
131     x and y of the element, the element should be positioned absolute. You can also control which handles are displayed by setting the "handles" attribute.
132     The handles are styled using CSS so they can be customized to look however you would like them to. 
133 </p>
134
135 <p>
136     This image has 8 way resizing, custom handles, is draggable and 8 way preserved ratio (that wasn't easy!).<br />
137     <b>Double click anywhere on the image to hide it when you are done.</b>
138 </p>
139 <img id="custom" src="sara_and_zack.jpg" width="200" height="152" style="position:absolute;left:0;top:0;"/>
140 <div style="padding:8px;border:1px solid #c3daf9;background:#d9e8fb;width:150px;text-align:center;"><button id="showMe">Show Me</button></div>
141 <pre class="code"><code>var custom = new Ext.Resizable('custom', {
142     wrap:true,
143     pinned:true,
144     minWidth:50,
145     minHeight: 50,
146     preserveRatio: true,
147     dynamic:true,
148     handles: 'all', // shorthand for 'n s e w ne nw se sw'
149     draggable:true
150 });</code></pre>
151 <hr>
152 <p>
153     <b>Snapping</b><br />
154
155     Resizable also supports basic snapping in increments. 
156 </p>
157 <div id="snap"></div>
158 <pre class="code"><code>var snap = new Ext.Resizable('snap', {
159     pinned:true,
160     width:250,
161     height:100,
162     handles: 'e',
163     widthIncrement:50,
164     minWidth: 50,
165     dynamic: true
166 });
167 </code></pre>
168 Warning: Snapping and preserveRatio conflict and can not be used together.
169 <hr>
170 <p>
171     <b>Animated Transitions</b><br />
172     Resize operations can also be animated. Animations support configurable easing and duration.
173     Here's a very basic clone of the first element, but with animation turned on. I used a "backIn"
174     easing and made it a little slower than default.
175 </p>
176 <div id="animated">Animate Me!</div>
177
178 <pre class="code"><code>var animated = new Ext.Resizable('animated', {
179     width: 200,
180     height: 100,
181     minWidth:100,
182     minHeight:50,
183     animate:true,
184     easing: 'backIn',
185     duration:.6
186 });</code></pre>
187 Warning: for obvious reasons animate and dynamic resizing can not be used together.
188 <hr>
189
190
191 <div id="box1" style="position:absolute; left:400px;padding:10px;border:1px solid #c3daf9;background:#d9e8fb;width:150px;text-align:center;">Boxes 1</div>
192 <div id="box2" style="position:absolute; left:600px;padding:20px;border:1px solid #c3daf9;background:#d9e8fb;width:150px;text-align:center;">Boxes 2</div>
193 <div id="box3" style="position:absolute; left:830px;padding:30px;border:1px solid #c3daf9;background:#d9e8fb;width:150px;text-align:center;">Boxes 3</div>
194
195 <!--<div id="grouping" style="background: none repeat scroll 0px 0px;height: 200px; left: 400px; opacity: 0.7; position: relative;">-->
196     
197 </div>
198
199
200 <pre class="code">
201 <code>var custom = new Ext.Resizable('custom', {
202     wrap:true,
203     pinned:true,
204     minWidth:50,
205     minHeight: 50,
206     preserveRatio: true,
207     dynamic:true,
208     handles: 'all', // shorthand for 'n s e w ne nw se sw'
209     draggable:true
210 });</code>
211 </pre>
212
213 </body>
214 </html>