5
<title>Example: Constrain a Resize</title>
6
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
<link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
<link rel="stylesheet" href="../assets/css/main.css">
9
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
<script src="../../build/yui/yui-min.js"></script>
15
<h1>Example: Constrain a Resize</h1>
18
<a href="#toc" class="jump">Jump to Table of Contents</a>
22
<div class="yui3-u-3-4">
24
<div class="content"><div class="intro">
25
<p>This example shows how to create a resizable element where the resize operation is constrained to a specific aspect ratio.</p>
33
border: 1px solid black;
34
background-color: #8DD5E7;
43
<div id="demo">Resize Me</div>
48
YUI().use('resize', function(Y) {
49
var resize = new Y.Resize({
50
//Selector of the node to resize
53
resize.plug(Y.Plugin.ResizeConstrained, {
67
<h3 id="setting-up-the-node">Setting up the Node</h3>
68
<p>First we need to create an HTML element to make resizable.</p>
70
<pre class="code prettyprint"><div id="demo">Resize Me</div></pre>
73
<p>Next, we'll give that element some CSS to make it visible.</p>
75
<pre class="code prettyprint">#demo {
78
border: 1px solid black;
79
background-color: #8DD5E7;
86
<h3 id="setting-up-the-yui-instance">Setting up the YUI Instance</h3>
88
<p>Now we need to create our YUI instance and tell it to load the <code>resize</code> module. This module is a rollup that includes the <code>resize-constrain</code> submodule; that means we have access to the <code>ResizeConstrained</code> plugin.</p>
90
<pre class="code prettyprint">YUI().use('resize');</pre>
94
<h3 id="making-the-node-resizable">Making the Node resizable</h3>
95
<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 Node.</p>
97
<pre class="code prettyprint">YUI().use('resize', function(Y) {
98
var resize = new Y.Resize({
99
//Selector of the node to resize
100
node: '#demo'
105
<h3 id="adding-the-constrained-plugin">Adding the Constrained Plugin</h3>
107
<p>Now we will plug <code>ResizeConstrained</code> into our Resize instance. This plugin will allow you to limit the resize dimensions in special ways.</p>
109
<pre class="code prettyprint">YUI().use('resize', function(Y) {
110
var resize = new Y.Resize({
111
//Selector of the node to resize
112
node: '#demo'
114
resize.plug(Y.Plugin.ResizeConstrained, {
124
<p>In this case, we've used the constraint feature to specify minimum height and width for the element while setting <code>preserveRatio</code> to <code>true</code>, locking in the original aspect ratio for the element.</p>
130
<div class="yui3-u-1-4">
131
<div class="sidebar">
133
<div id="toc" class="sidebox">
135
<h2 class="no-toc">Table of Contents</h2>
141
<a href="#setting-up-the-node">Setting up the Node</a>
144
<a href="#setting-up-the-yui-instance">Setting up the YUI Instance</a>
147
<a href="#making-the-node-resizable">Making the Node resizable</a>
150
<a href="#adding-the-constrained-plugin">Adding the Constrained Plugin</a>
158
<div class="sidebox">
160
<h2 class="no-toc">Examples</h2>
164
<ul class="examples">
167
<li data-description="Resize a node.">
168
<a href="simple-resize.html">Simple Resize</a>
173
<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.">
174
<a href="constrain-resize.html">Constrain a Resize</a>
179
<li data-description="This example shows an 8-way image resize, providing the CSS needed for a common image-resize visual treatment.">
180
<a href="image-resize.html">8-way Image Resize</a>
185
<li data-description="Plugs a widget with resize functionality.">
186
<a href="simple-resize-plugin.html">Widget with simple Resize Plugin</a>
191
<li data-description="Plugs a widget with resize functionality, and implements ResizeConstrained">
192
<a href="constrain-resize-plugin.html">Widget with Resize Plugin under constraints</a>
207
<script src="../assets/vendor/prettify/prettify-min.js"></script>
208
<script>prettyPrint();</script>