Resize Utility: Simple Resize with Constrain Plugin
This example shows a simple constrained node resize.
Resize Me
Setting up the Node
First we need to create an HTML Node to make resizable.
<div id="demo">Resize Me</div>
<div id="demo">Resize Me</div>
Now we give that Node some CSS to make it visible.
#demo { height: 100px; width: 100px; border: 1px solid black; background-color: #8DD5E7; cursor: move; position: relative; }
#demo { height: 100px; width: 100px; border: 1px solid black; background-color: #8DD5E7; cursor: move; position: relative; }
Setting up the YUI Instance
Now we need to create our YUI instance and tell it to load the resize
module.
YUI().use('resize');
YUI().use('resize');
Making the Node resizable
Now that we have a YUI instance with the resize
module, we need to instantiate the Resize
instance on this Node.
YUI().use('resize', function(Y) { var resize = new Y.Resize({ //Selector of the node to resize node: '#demo' }); });
YUI().use('resize', function(Y) { var resize = new Y.Resize({ //Selector of the node to resize node: '#demo' }); });
Adding the Constrained Plugin
Now we will add the contrained plugin. This plugin will allow you to limit the resize dimensions in special ways.
YUI().use('resize', function(Y) { var resize = new Y.Resize({ //Selector of the node to resize node: '#demo' }); resize.plug(Y.Plugin.ResizeConstrained, { minWidth: 50, minHeight: 50, maxWidth: 300, maxHeight: 300, preserveRatio: true }); });
YUI().use('resize', function(Y) { var resize = new Y.Resize({ //Selector of the node to resize node: '#demo' }); resize.plug(Y.Plugin.ResizeConstrained, { minWidth: 50, minHeight: 50, maxWidth: 300, maxHeight: 300, preserveRatio: true }); });