调整大小(Resizable)


演示(demo)地址在文章最后.

效果图如下

主要文件basic.html,basic.js,basic.css。

basic.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Resizable Examples</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />

   <!-- GC -->
 	<!-- LIBS -->
 	<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
 	<!-- ENDLIBS -->

    <script type="text/javascript" src="../../ext-all.js"></script>
<script language="javascript" src="basic.js"></script>

<!-- Common Styles for the examples -->
<link rel="stylesheet" type="text/css" href="../examples.css" />
<style type="text/css">
#basic, #animated {
    border:1px solid #c3daf9;
    color:#1e4e8f;
    font:bold 14px tahoma,verdana,helvetica;
    text-align:center;
    padding-top:20px;
}
#snap {
    border:1px solid #c3daf9;
    overflow:hidden;
}
#custom {
    cursor:move;
}
#custom-rzwrap{
    z-index: 100;
}
#custom-rzwrap .x-resizable-handle{
    width:11px;
    height:11px;
    background:transparent url(../../resources/images/default/sizer/square.gif) no-repeat;
    margin:0px;
}
#custom-rzwrap .x-resizable-handle-east, #custom-rzwrap .x-resizable-handle-west{
    top:45%;
}
#custom-rzwrap .x-resizable-handle-north, #custom-rzwrap .x-resizable-handle-south{
    left:45%;
}
</style>
</head>

<body>
<script type="text/javascript" src="../examples.js"></script><!-- EXAMPLES -->
<h1>Resizable Examples</h1>
<p>These examples show how to apply a floating (default) and pinned Resizable component to a standard element.</p>
<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>

<p>
    <b>Basic Example</b><br />
    This is a basic as you get. To resize the box, position your mouse anywhere near the bottom,
    right or border right edge of the box. This example uses the default "floating" handles.
</p>
<div id="basic">Resize Me!</div>
<pre class="code"><code>var basic = new Ext.Resizable('basic', {
        width: 200,
        height: 100,
        minWidth:100,
        minHeight:50
});</code></pre>
<hr>
<p>
    <b>Wrapped Elements</b><br />
    Some elements such as images and textareas don't allow child elements. In the past, you had
    to wrap these elements and set up a Resizable with resize child. Resizable will
    wrap the element, calculate adjustments for borders/padding and offset the handles for you. All you have to
    do is set "wrap:true". The manual way of specifying a "resizeChild" is still supported as well.
</p><p>
    <b>Pinned Handles</b><br />
    Notice this example has the resize handles "pinned". This is done by setting "pinned:true".
</p><p>
    <b>Dynamic Sizing</b><br />
    If you don't like the proxy resizing, you can also turn on dynamic sizing. Just set "dynamic:true".
</p>
<p>
    Here's a textarea that is wrapped, has pinned handles and has dynamic sizing turned on.
</p>
<textarea id="dwrapped">
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.
Vivamus eget quam. Vivamus tincidunt diam nec urna. Curabitur velit. Quisque dolor magna, ornare sed, elementum porta, luctus in, leo.
</textarea><br /><br />
And look how simple the code is, even my grandma could write it.
<pre class="code"><code>var dwrapped = new Ext.Resizable('dwrapped', {
    wrap:true,
    pinned:true,
    width:450,
    height:150,
    minWidth:200,
    minHeight: 50,
    dynamic: true
});</code></pre>
<hr>
<p>
<b>Preserve Ratio</b><br />
    For some things like images, you will probably want to preserve the ratio of width to height. Just set preserveRatio:true.
</p>
<img id="wrapped" src="sara.jpg" width="200" height="250"/>
<pre class="code"><code>var wrapped = new Ext.Resizable('wrapped', {
    wrap:true,
    pinned:true,
    minWidth:50,
    minHeight: 50,
    preserveRatio: true
});</code></pre>
<hr>
<p>
<b>Transparent Handles</b><br />
    If you just want the element to be resizable without any fancy handles, set transparent to true.
</p>
<img id="transparent" src="zack.jpg" width="100" height="176"/>
<pre class="code"><code>var transparent = new Ext.Resizable('transparent', {
    wrap:true,
    minWidth:50,
    minHeight: 50,
    preserveRatio: true,
    transparent:true
});</code></pre>
<hr>
<p>
    <b>Customizable Handles</b><br />
    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
    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.
    The handles are styled using CSS so they can be customized to look however you would like them to. 
</p>
<p>
    This image has 8 way resizing, custom handles, is draggable and 8 way preserved ratio (that wasn't easy!).<br />
    <b>Double click anywhere on the image to hide it when you are done.</b>
</p>
<img id="custom" src="sara_and_zack.jpg" width="200" height="152" style="position:absolute;left:0;top:0;"/>
<div style="padding:8px;border:1px solid #c3daf9;background:#d9e8fb;width:150px;text-align:center;"><button id="showMe">Show Me</button></div>
<pre class="code"><code>var custom = new Ext.Resizable('custom', {
    wrap:true,
    pinned:true,
    minWidth:50,
    minHeight: 50,
    preserveRatio: true,
    dynamic:true,
    handles: 'all', // shorthand for 'n s e w ne nw se sw'
    draggable:true
});</code></pre>
<hr>
<p>
    <b>Snapping</b><br />
    Resizable also supports basic snapping in increments. 
</p>
<div id="snap"></div>
<pre class="code"><code>var snap = new Ext.Resizable('snap', {
    pinned:true,
    width:250,
    height:100,
    handles: 'e',
    widthIncrement:50,
    minWidth: 50,
    dynamic: true
});
</code></pre>
Warning: Snapping and preserveRatio conflict and can not be used together.
<hr>
<p>
    <b>Animated Transitions</b><br />
    Resize operations can also be animated. Animations support configurable easing and duration.
    Here's a very basic clone of the first element, but with animation turned on. I used a "backIn"
    easing and made it a little slower than default.
</p>
<div id="animated">Animate Me!</div>
<pre class="code"><code>var animated = new Ext.Resizable('animated', {
    width: 200,
    height: 100,
    minWidth:100,
    minHeight:50,
    animate:true,
    easing: 'backIn',
    duration:.6
});</code></pre>
Warning: for obvious reasons animate and dynamic resizing can not be used together.
</body>
</html>

basic.js

/*
 * Ext JS Library 2.0.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * extjs.com/license
 */

var ResizableExample = {
    init : function(){
        
        var basic = new Ext.Resizable('basic', {
                width: 200,
                height: 100,
                minWidth:100,
                minHeight:50
        });
        
        var animated = new Ext.Resizable('animated', {
                width: 200,
                pinned: true,
                height: 100,
                minWidth:100,
                minHeight:50,
                animate:true,
                easing: 'backIn',
                duration:.6
        });
        
        var wrapped = new Ext.Resizable('wrapped', {
            wrap:true,
            pinned:true,
            minWidth:50,
            minHeight: 50,
            preserveRatio: true
        });
        
        var transparent = new Ext.Resizable('transparent', {
            wrap:true,
            minWidth:50,
            minHeight: 50,
            preserveRatio: true,
            transparent:true
        });
        
        var custom = new Ext.Resizable('custom', {
            wrap:true,
            pinned:true,
            minWidth:50,
            minHeight: 50,
            preserveRatio: true,
            handles: 'all',
            draggable:true,
            dynamic:true
        });
        var customEl = custom.getEl();
        // move to the body to prevent overlap on my blog
        document.body.insertBefore(customEl.dom, document.body.firstChild);
        
        customEl.on('dblclick', function(){
            customEl.hide(true);
        });
        customEl.hide();
        
        Ext.get('showMe').on('click', function(){
            customEl.center();
            customEl.show(true);
        });
        
        var dwrapped = new Ext.Resizable('dwrapped', {
            wrap:true,
            pinned:true,
            width:450,
            height:150,
            minWidth:200,
            minHeight: 50,
            dynamic: true
        });
        
        var snap = new Ext.Resizable('snap', {
            pinned:true,
            width:250,
            height:100,
            handles: 'e',
            widthIncrement:50,
            minWidth: 50,
            dynamic: true
        });
    }
};

Ext.EventManager.onDocumentReady(ResizableExample.init, ResizableExample, true);

basic.css

/*
 * Ext JS Library 2.0.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * extjs.com/license
 */

#basic, #animated {
    border:1px solid #c3daf9;
    color:#1e4e8f;
    font:bold 14px tahoma,verdana,helvetica;
    text-align:center;
    padding-top:20px;
	 width:200px;
	 height:80px;
}
#snap {
    border:1px solid #c3daf9;
    overflow:hidden;
}
#custom {
    cursor:move;
}
#custom-rzwrap{
    z-index: 10000;
}
#custom-rzwrap .x-resizable-handle{
    width:11px;
    height:11px;
    background:transparent url(../../resources/images/sizer/square.gif) no-repeat;
    margin:0px;
	 line-height:11px;
}
#custom-rzwrap .x-resizable-handle-east, #custom-rzwrap .x-resizable-handle-west{
    top:45%;
}
#custom-rzwrap .x-resizable-handle-north, #custom-rzwrap .x-resizable-handle-south{
    left:45%;
}

演示地址:http://extjs.org.cn/extjs/examples/resizable/basic.html

评论

World Products

American Auto Accessories American Bracelets American Caps American Car Parts American Clothing American Coal American Cosmetics American Cotton American Cranes American Cutlery American Denim American Dinnerware American Fleece American Football Jersey American Forklift American Furniture American Gemstones American Ginseng American Glassware American Grain American Granite American Gypsum American Handbags American Hardwoods American Iron Ore American Leather American Lingerie American Lumber American Machinery American Maize American Marble American Napkins American Nba Jersey American Patio Furniture American Perfumes American Power Supply American Propane American Refrigerators American Rice American Sewing Machine American Silicon American Soaps American Steel American Swimwear American Tents American Truck Parts American Used Cars American Wedding Dresses American Wheat American Zinc Canada Clothing Canada Solar Panels China Aluminum China Anion Purifier China Atv China Atv Parts China Auto Parts China Automobile China Auto Parts China Automobile China Auto Parts China Automobile China Auto Parts China Automobile China Auto Parts China Automobile China Auto Parts China Basketball Shoes China Bathmats China Battery China Beads China Bearing China Bedding China Belts China Bicycles China Blanket China Boats China Bowls China Bracelet China Bracelets China Buggies China Buses China Cabinets China Candle Holders China Casting China Ceramic Tiles China Chairs China Charms China Clay China Clinker China Clogs China Clothes China Coffins China Construction Machinery China Cooker China Crocs China Crude Oil China Curtains China Cutting Machine China Dental Chair China Digital Camera China Digital Frame China Digital Timer China Dirt Bikes China Dome Camera China Door China Dvds China E Cigarettes China Electric Bicycles China Electric Scooter China Eva Slipper China Eye Glasses China Fabric China Faucet China Fishing Tackle China Fitting China Flashlight China Flooring China Furniture China Gadgets China Gas Scooter China Gas Scooters China Gasket China Gemstones China Generator China Gifts China Gloves China Golf Cart China Gps Tracker China Granite China Grinder China Hair Straightener China Handbags China Handicraft China Hgh China Inflatable China Inflatables China Ink Cartridge China Iron China Jackets China Jerseys China Jewelry China Kayak China Keyrings China Kitchenware China Lace China Leather Belts China Leather Sofas China LED China Lens China Lighting China Lights China Lubricants China Lumber China Machinery China Magnet China Marble China Markers China Masks China Mattress China Medicine China Memory Stick China Microfiber China Mini Laptop China Mobile Phones China Mobiles China Modern Furniture China Moped China Mosaics China Motorcycles China Motors China Mp3 Players China Nail China Necklace China Office Furniture China Paintball China Pants China Pcb China Pendant China Perfumes China Pet Bed China Pigment China Plates China Pumps China Purse China Pvc Pipe China Quads China Quartz China Quilts China Rack China Radiator China Rattan Furniture China Rhinestones China Rims China Rings China Rope China Rugs China Safety Vests China Scaffold China Scarf China Scooters China Scraps China Shirts China Shoes China Shower Enclosure China Slim Tea China Socks China Solar Panels China Speakers China Steel China Steel Pipes China Steroids China Suits China Sunglasses China Swarovski China Sweaters China T Shirts China Tea China Tea Sets China Toners China Torch China Tote China Towels China Toys China Tractors China Trawler China Treadmill China Trucks China Tyres China USB China Valve China Veneer China Wallet China Watches China Water Filter China Wax China Wedding Rings China Wheelchairs China Wigs China Wire China Wooden Furniture China Xenon HID China Yarn China Zinc Chinese Atv Parts Chinese Bedding Chinese Guitars Chinese Jewelry Chinese Laptops Chinese Lingerie Chinese Motorcycle Chinese Shoes Egyptian Cotton German Cars German Furniture German Jewelry German Leather German Machinery German Machines German Timber German Used Cars German Watches German Wedding Dresses Germany Cars Germany Generators Italy Shoes Jamaican Stone Japan Auto Parts Japan Cars Japanese Auto Accessories Japanese Auto Parts Japanese Car Parts Japanese Cars Japanese Crane Japanese Engines Japanese Furniture Japanese Generators Japanese Jewelry Japanese Machinery Japanese Machines Japanese Mini Trucks Japanese Motorcycles Japanese Scooters Japanese Tires Japanese Toys Japanese Trucks Japanese Used Cars Japanese Used Trucks Japanese Used Vehicles Japanese Vehicles Malaysia Palm Oil Pakistan Furniture Peru Silver Jewelry Portuguese Shoes Sri Lanka Furniture Turkey Dresses Vietnamese Clothing Vietnamese Furniture