5
<title>Example: 8-way Image Resize</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
14
<h1>Example: 8-way Image Resize</h1>
17
<a href="#toc" class="jump">Jump to Table of Contents</a>
21
<div id="main" class="yui3-u">
22
<div class="content"><div class="intro">
23
<p>This example shows a simple 8-way image resize and provides the required CSS elements required for the most common image-resize visual treatment.</p>
29
display: block; // fixes image misalignment
41
border: 1px solid black;
44
/* knob handles demo */
46
.yui3-resize-knob .yui3-resize-handle-tr,
47
.yui3-resize-knob .yui3-resize-handle-br,
48
.yui3-resize-knob .yui3-resize-handle-tl,
49
.yui3-resize-knob .yui3-resize-handle-bl,
50
.yui3-resize-knob .yui3-resize-handle-b,
51
.yui3-resize-knob .yui3-resize-handle-t,
52
.yui3-resize-knob .yui3-resize-handle-l,
53
.yui3-resize-knob .yui3-resize-handle-r {
54
border: 1px solid #808080;
55
background-color: #F2F2F2;
60
.yui3-resize-knob .yui3-resize-handle-b,
61
.yui3-resize-knob .yui3-resize-handle-t {
65
.yui3-resize-knob .yui3-resize-handle-l,
66
.yui3-resize-knob .yui3-resize-handle-r {
70
.yui3-resize-knob .yui3-resize-handle-t,
71
.yui3-resize-knob .yui3-resize-handle-tr,
72
.yui3-resize-knob .yui3-resize-handle-tl {
76
.yui3-resize-knob .yui3-resize-handle-b,
77
.yui3-resize-knob .yui3-resize-handle-br,
78
.yui3-resize-knob .yui3-resize-handle-bl {
82
.yui3-resize-knob .yui3-resize-handle-l,
83
.yui3-resize-knob .yui3-resize-handle-bl,
84
.yui3-resize-knob .yui3-resize-handle-tl {
88
.yui3-resize-knob .yui3-resize-handle-r,
89
.yui3-resize-knob .yui3-resize-handle-br,
90
.yui3-resize-knob .yui3-resize-handle-tr {
94
.yui3-resize-knob .yui3-resize-handle-inner {
102
<div id="demoContainer" class="yui3-resize-knob">
103
<img id="demo" src="../assets/resize/team.jpg" alt="Eduardo Lundgren, Nate Cavanaugh and the YUI Team at Yahoo">
110
YUI().use('resize', function(Y) {
111
var resize = new Y.Resize({
112
//Selector of the node to resize
115
resize.plug(Y.Plugin.ResizeConstrained, {
116
constrain: '#demoContainer',
129
<h3 id="setting-up-the-node">Setting up the Node</h3>
130
<p>First we need to create an image to resize; we wrap the image in another element to provide some CSS hooks.</p>
132
<pre class="code prettyprint"><div id="demoContainer" class="yui3-resize-knob">
133
<img id="demo" src="../assets/resize/team.jpg" alt="Eduardo Lundgren, Nate Cavanaugh and the YUI Team at Yahoo">
134
</div></pre>
137
<h3 id="setting-up-the-yui-instance">Setting up the YUI Instance</h3>
138
<p>Next, we need to create our YUI instance and tell it to load the <code>resize</code> module.</p>
140
<pre class="code prettyprint">YUI().use('resize');</pre>
143
<h3 id="making-the-node-resizable">Making the Node Resizable</h3>
144
<p>Now that we have a YUI instance with the <code>resize</code> module, we need to instantiate the <code>Resize</code> instance on this element.</p>
146
<pre class="code prettyprint">YUI().use('resize', function(Y) {
147
var resize = new Y.Resize({
148
//Selector of the node to resize
149
node: '#demo'
155
<h3 id="adding-the-constrained-plugin">Adding the Constrained Plugin</h3>
156
<p>Now we add the <code>ResizeConstrained</code> plugin. This plugin will allow you to limit the resize dimensions in special ways.</p>
159
<pre class="code prettyprint">YUI().use('resize', function(Y) {
160
var resize = new Y.Resize({
161
//Selector of the node to resize
162
node: '#demo'
164
resize.plug(Y.Plugin.ResizeConstrained, {
165
constrain: '#demoContainer',
172
<h3 id="adding-css">Adding CSS</h3>
174
<p>Image resize operations typically have their own visual treatment and therefore require slightly different drag handles in order to be discoverable and intuitive. Here is CSS that provides a common image-resize visual treatment:</p>
176
<pre class="code prettyprint">#demo {
177
display: block; // fixes image misalignment
189
border: 1px solid black;
192
/* knob handles demo */
194
.yui3-resize-knob .yui3-resize-handle-tr,
195
.yui3-resize-knob .yui3-resize-handle-br,
196
.yui3-resize-knob .yui3-resize-handle-tl,
197
.yui3-resize-knob .yui3-resize-handle-bl,
198
.yui3-resize-knob .yui3-resize-handle-b,
199
.yui3-resize-knob .yui3-resize-handle-t,
200
.yui3-resize-knob .yui3-resize-handle-l,
201
.yui3-resize-knob .yui3-resize-handle-r {
202
border: 1px solid #808080;
203
background-color: #F2F2F2;
208
.yui3-resize-knob .yui3-resize-handle-b,
209
.yui3-resize-knob .yui3-resize-handle-t {
213
.yui3-resize-knob .yui3-resize-handle-l,
214
.yui3-resize-knob .yui3-resize-handle-r {
218
.yui3-resize-knob .yui3-resize-handle-t,
219
.yui3-resize-knob .yui3-resize-handle-tr,
220
.yui3-resize-knob .yui3-resize-handle-tl {
224
.yui3-resize-knob .yui3-resize-handle-b,
225
.yui3-resize-knob .yui3-resize-handle-br,
226
.yui3-resize-knob .yui3-resize-handle-bl {
230
.yui3-resize-knob .yui3-resize-handle-l,
231
.yui3-resize-knob .yui3-resize-handle-bl,
232
.yui3-resize-knob .yui3-resize-handle-tl {
236
.yui3-resize-knob .yui3-resize-handle-r,
237
.yui3-resize-knob .yui3-resize-handle-br,
238
.yui3-resize-knob .yui3-resize-handle-tr {
242
.yui3-resize-knob .yui3-resize-handle-inner {
251
<div id="sidebar" class="yui3-u">
253
<div id="toc" class="sidebox">
255
<h2 class="no-toc">Table of Contents</h2>
261
<a href="#setting-up-the-node">Setting up the Node</a>
264
<a href="#setting-up-the-yui-instance">Setting up the YUI Instance</a>
267
<a href="#making-the-node-resizable">Making the Node Resizable</a>
270
<a href="#adding-the-constrained-plugin">Adding the Constrained Plugin</a>
273
<a href="#adding-css">Adding CSS</a>
281
<div class="sidebox">
283
<h2 class="no-toc">Examples</h2>
287
<ul class="examples">
290
<li data-description="Resize a node.">
291
<a href="simple-resize.html">Simple Resize</a>
296
<li data-description="A simple resize implementation that utilizes the ResizeConstrained plugin to set min/max dimensions and to lock in the resized element's aspect ratio.">
297
<a href="constrain-resize.html">Constrain a Resize</a>
302
<li data-description="This example shows an 8-way image resize, providing the CSS needed for a common image-resize visual treatment.">
303
<a href="image-resize.html">8-way Image Resize</a>
308
<li data-description="Plugs a widget with resize functionality.">
309
<a href="simple-resize-plugin.html">Widget with simple Resize Plugin</a>
314
<li data-description="Plugs a widget with resize functionality, and implements ResizeConstrained">
315
<a href="constrain-resize-plugin.html">Widget with Resize Plugin under constraints</a>
329
<script src="../assets/vendor/prettify/prettify-min.js"></script>
330
<script>prettyPrint();</script>