JavaScript DHTML/jQuery/UI Resizable

Материал из Web эксперт
Перейти к: навигация, поиск

Animated resizable

 
<html lang="en">
<head>
  <title></title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <script type="text/javascript">
    $(function() {
        var resizeOpts = {
          helper: "proxy",
          knobHandles: true,
          animate: true,
          animateDuration: "fast"  
        }
        $(".resize").resizable(resizeOpts);
    });
  </script>
</head>
<body>
    <div class="resize">
      <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse auctor ligula vel odio. Nam et sem vitae nibh convallis euismod. Aenean vitae urna quis augue adipiscing hendrerit. Nam faucibus. Phasellus eros. Ut bibendum eros at nibh. Sed erat. Aenean id enim vitae leo aliquet rutrum. Mauris fringilla euismod orci. Morbi tempus purus eget felis. Sed dui eros, tempor id, iaculis vel, pretium eget, nunc. Pellentesque vehicula tincidunt arcu. Ut a velit. In dapibus, lacus vitae lobortis dictum, libero pede venenatis magna, eu sagittis nunc erat sed ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus est dolor, mollis congue, ullamcorper eu, auctor ut, augue.</div>
    </div>
</body>
</html>



containment: ".container", aspectRatio: true

 
<html lang="en">
<head>
  <title></title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <script type="text/javascript">
    $(function() {
        var resizeOpts = {
          containment: ".container",
          aspectRatio: true
        }
        $(".resize").resizable(resizeOpts);
    });
  </script>
</head>
<body>
    <div class="resize">
      <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse auctor ligula vel odio. Nam et sem vitae nibh convallis euismod. Aenean vitae urna quis augue adipiscing hendrerit. Nam faucibus. Phasellus eros. Ut bibendum eros at nibh. Sed erat. Aenean id enim vitae leo aliquet rutrum. Mauris fringilla euismod orci. Morbi tempus purus eget felis. Sed dui eros, tempor id, iaculis vel, pretium eget, nunc. Pellentesque vehicula tincidunt arcu. Ut a velit. In dapibus, lacus vitae lobortis dictum, libero pede venenatis magna, eu sagittis nunc erat sed ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus est dolor, mollis congue, ullamcorper eu, auctor ut, augue.</div>
    </div>
</body>
</html>



Get resized height and width

 
<html lang="en">
<head>
  <title></title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <script type="text/javascript">
    $(function() {
        var resizeOpts = {
          stop: reportNewSize  
        };
        function reportNewSize() {
          alert($(this).height() + " pixels high, and " + $(this).width() + " pixels wide");
        }
        $(".resize").resizable(resizeOpts);
    });
  </script>
</head>
<body>
    <div class="resize">
      <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse auctor ligula vel odio. Nam et sem vitae nibh convallis euismod. Aenean vitae urna quis augue adipiscing hendrerit. Nam faucibus. Phasellus eros. Ut bibendum eros at nibh. Sed erat. Aenean id enim vitae leo aliquet rutrum. Mauris fringilla euismod orci. Morbi tempus purus eget felis. Sed dui eros, tempor id, iaculis vel, pretium eget, nunc. Pellentesque vehicula tincidunt arcu. Ut a velit. In dapibus, lacus vitae lobortis dictum, libero pede venenatis magna, eu sagittis nunc erat sed ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus est dolor, mollis congue, ullamcorper eu, auctor ut, augue.</div>
    </div>
</body>
</html>



ghost your resizable

 
<html lang="en">
<head>
  <title></title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <script type="text/javascript">
    $(function() {
        var resizeOpts = {
          ghost: true
        }
        $(".resize").resizable(resizeOpts);
    });
  </script>
</head>
<body>
    <div class="resize">
      <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse auctor ligula vel odio. Nam et sem vitae nibh convallis euismod. Aenean vitae urna quis augue adipiscing hendrerit. Nam faucibus. Phasellus eros. Ut bibendum eros at nibh. Sed erat. Aenean id enim vitae leo aliquet rutrum. Mauris fringilla euismod orci. Morbi tempus purus eget felis. Sed dui eros, tempor id, iaculis vel, pretium eget, nunc. Pellentesque vehicula tincidunt arcu. Ut a velit. In dapibus, lacus vitae lobortis dictum, libero pede venenatis magna, eu sagittis nunc erat sed ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus est dolor, mollis congue, ullamcorper eu, auctor ut, augue.</div>
    </div>
</body>
</html>



jQuery UI Resizable - Animate

  

<!--
  jQuery UI Effects Blind 1.7.2
 
  Copyright (c) 2009 AUTHORS.txt (http://jqueryui.ru/about)
  Dual licensed under the MIT (MIT-LICENSE.txt)
  and GPL (GPL-LICENSE.txt) licenses.
 
 
-->
<!doctype html>
<html lang="en">
<head>
  <title>jQuery UI Resizable - Animate</title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <style type="text/css">
  #resizable { width: 150px; height: 150px; padding: 0.5em; }
  #resizable h3 { text-align: center; margin: 0; }
  .ui-resizable-helper { border: 1px dotted gray; }
  </style>
  <script type="text/javascript">
  $(function() {
    $("#resizable").resizable({
      animate: true
    });
  });
  </script>
</head>
<body>
<div class="demo">
  
<div id="resizable" class="ui-widget-content">
  <h3 class="ui-widget-header">Animate</h3>
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>Animate the resize action using the <code>animate</code> option (boolean). When this option is set to true, drag the outline to the desired location; the element animates to that size on drag stop.</p>
</div><!-- End demo-description -->
</body>
</html>



jQuery UI Resizable - Constrain resize area

  
<!--
  jQuery UI Effects Blind 1.7.2
 
  Copyright (c) 2009 AUTHORS.txt (http://jqueryui.ru/about)
  Dual licensed under the MIT (MIT-LICENSE.txt)
  and GPL (GPL-LICENSE.txt) licenses.
 
 
-->
<!doctype html>
<html lang="en">
<head>
  <title>jQuery UI Resizable - Constrain resize area</title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <style type="text/css">
  #container { width: 300px; height: 300px; }
  #container h3 { text-align: center; margin: 0; margin-bottom: 10px; }
  #resizable { background-position: top left; width: 150px; height: 150px; }
  #resizable, #container { padding: 0.5em; }
  </style>
  <script type="text/javascript">
  $(function() {
    $("#resizable").resizable({
      containment: "#container"
    });
  });
  </script>
</head>
<body>
<div class="demo">
  
<div id="container" class="ui-widget-content">
  <h3 class="ui-widget-header">Containment</h3>
  <div id="resizable" class="ui-state-active">
    <h3 class="ui-widget-header">Resizable</h3>
  </div>
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>Define the boundaries of the resizable area. Use the <code>containment</code> option to specify a parent DOM element or a jQuery selector, like "document."</p>
</div><!-- End demo-description -->
</body>
</html>



jQuery UI Resizable - Default functionality

  

<!--
  jQuery UI Effects Blind 1.7.2
 
  Copyright (c) 2009 AUTHORS.txt (http://jqueryui.ru/about)
  Dual licensed under the MIT (MIT-LICENSE.txt)
  and GPL (GPL-LICENSE.txt) licenses.
 
 
-->
<!doctype html>
<html lang="en">
<head>
  <title>jQuery UI Resizable - Default functionality</title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <style type="text/css">
  #resizable { width: 150px; height: 150px; padding: 0.5em; }
  #resizable h3 { text-align: center; margin: 0; }
  </style>
  <script type="text/javascript">
  $(function() {
    $("#resizable").resizable();
  });
  </script>
</head>
<body>
<div class="demo">
  
<div id="resizable" class="ui-widget-content">
  <h3 class="ui-widget-header">Resizable</h3>
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>Enable any DOM element to be resizable.  With the cursor grab the right or bottom border and drag to the desired width or height.</p>
</div><!-- End demo-description -->
</body>
</html>



jQuery UI Resizable - Delay start

  
<!--
  jQuery UI Effects Blind 1.7.2
 
  Copyright (c) 2009 AUTHORS.txt (http://jqueryui.ru/about)
  Dual licensed under the MIT (MIT-LICENSE.txt)
  and GPL (GPL-LICENSE.txt) licenses.
 
 
-->
<!doctype html>
<html lang="en">
<head>
  <title>jQuery UI Resizable - Delay start</title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <style type="text/css">
  #resizable, #resizable2 { width: 150px; height: 150px; padding: 0.5em; }
  #resizable h3, #resizable2 h3 { text-align: center; margin: 0; }
  </style>
  <script type="text/javascript">
  $(function() {
    $("#resizable").resizable({
      delay: 1000
    });
    
    $("#resizable2").resizable({
      distance: 40
    });
  });
  </script>
</head>
<body>
<div class="demo">
  
<h3 class="docs">Time delay (ms):</h3>
<div id="resizable" class="ui-widget-content">
  <h3 class="ui-widget-header">Time</h3>
</div>
<h3 class="docs">Distance delay (px):</h3>
<div id="resizable2" class="ui-widget-content">
  <h3 class="ui-widget-header">Distance</h3>
</div>
<!-- ADD DISTANCE DEMO -->
</div><!-- End demo -->
<div class="demo-description">
<p>Delay the start of resizng for a number of milliseconds with the <code>delay</code> option; prevent resizing until the cursor is held down and dragged a specifed number of pixels with the <code>distance</code> option.</p>
</div><!-- End demo-description -->
</body>
</html>



jQuery UI Resizable - Maximum / minimum size

  
<!--
  jQuery UI Effects Blind 1.7.2
 
  Copyright (c) 2009 AUTHORS.txt (http://jqueryui.ru/about)
  Dual licensed under the MIT (MIT-LICENSE.txt)
  and GPL (GPL-LICENSE.txt) licenses.
 
 
-->
<!doctype html>
<html lang="en">
<head>
  <title>jQuery UI Resizable - Maximum / minimum size</title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <style type="text/css">
  #resizable { width: 200px; height: 150px; padding: 5px; }
  #resizable h3 { text-align: center; margin: 0; }
  </style>
  <script type="text/javascript">
  $(function() {
    $("#resizable").resizable({
      maxHeight: 250,
      maxWidth: 350,
      minHeight: 150,
      minWidth: 200
    });
  });
  </script>
</head>
<body>
<div class="demo">
  
<div id="resizable" class="ui-widget-content">
  <h3 class="ui-widget-header">Resize larger / smaller</h3>
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>Limit the resizable element to a maximum or minimum height or width using the <code>maxHeight</code>, <code>maxWidth</code>, <code>minHeight</code>, and <code>minWidth</code> options.</p>
</div><!-- End demo-description -->
</body>
</html>



jQuery UI Resizable - Preserve aspect ratio

  
<!--
  jQuery UI Effects Blind 1.7.2
 
  Copyright (c) 2009 AUTHORS.txt (http://jqueryui.ru/about)
  Dual licensed under the MIT (MIT-LICENSE.txt)
  and GPL (GPL-LICENSE.txt) licenses.
 
 
-->
<!doctype html>
<html lang="en">
<head>
  <title>jQuery UI Resizable - Preserve aspect ratio</title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <style type="text/css">
  #resizable { width: 160px; height: 90px; padding: 0.5em; }
  #resizable h3 { text-align: center; margin: 0; }
  </style>
  <script type="text/javascript">
  $(function() {
    $("#resizable").resizable({
      aspectRatio: 16/9
    });
  });
  </script>
</head>
<body>
<div class="demo">
  
<div id="resizable" class="ui-widget-content">
  <h3 class="ui-widget-header">Preserve aspect ratio</h3>
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>Maintain the existing aspect ratio or set a new one to constrain the proportions on resize. Set the <code>aspectRatio</code> option to true, and optionally pass in a new ratio (i.e., 4/3)</p>
</div><!-- End demo-description -->
</body>
</html>



jQuery UI Resizable - Snap to grid

  

<!--
  jQuery UI Effects Blind 1.7.2
 
  Copyright (c) 2009 AUTHORS.txt (http://jqueryui.ru/about)
  Dual licensed under the MIT (MIT-LICENSE.txt)
  and GPL (GPL-LICENSE.txt) licenses.
 
 
-->
<!doctype html>
<html lang="en">
<head>
  <title>jQuery UI Resizable - Snap to grid</title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <style type="text/css">
  #resizable { width: 150px; height: 150px; padding: 0.5em; }
  #resizable h3 { text-align: center; margin: 0; }
  </style>
  <script type="text/javascript">
  $(function() {
    $("#resizable").resizable({
      grid: 50
    });
  });
  </script>
</head>
<body>
<div class="demo">
  
<div id="resizable" class="ui-widget-content">
  <h3 class="ui-widget-header">Grid</h3>
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>Snap the resizable element to a grid.  Set the dimensions of grid cells (height and width in pixels) with the <code>grid</code> option.</p>
</div><!-- End demo-description -->
</body>
</html>



jQuery UI Resizable - Synchronous resize

  
<!--
  jQuery UI Effects Blind 1.7.2
 
  Copyright (c) 2009 AUTHORS.txt (http://jqueryui.ru/about)
  Dual licensed under the MIT (MIT-LICENSE.txt)
  and GPL (GPL-LICENSE.txt) licenses.
 
 
-->
<!doctype html>
<html lang="en">
<head>
  <title>jQuery UI Resizable - Synchronous resize</title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <style type="text/css">
  #resizable { background-position: top left; }
  #resizable, #also { width: 150px; height: 120px; padding: 0.5em; }
  #resizable h3, #also h3 { text-align: center; margin: 0; }
  #also { margin-top: 1em; }
  </style>
  <script type="text/javascript">
  $(function() {
    $("#resizable").resizable({
      alsoResize: "#also"
    });
    $("#also").resizable();
  });
  </script>
</head>
<body>
<div class="demo">
  
<div id="resizable" class="ui-widget-header">
  <h3 class="ui-state-active">Resize</h3>
</div>
<div id="also" class="ui-widget-content">
  <h3 class="ui-widget-header">will also resize</h3>
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>Resize multiple elements simultaneously by clicking and dragging the sides of one.  Pass a shared selector into the <code>alsoResize</code> option.</p>
</div><!-- End demo-description -->
</body>
</html>



jQuery UI Resizable - Visual feedback

  
<!--
  jQuery UI Effects Blind 1.7.2
 
  Copyright (c) 2009 AUTHORS.txt (http://jqueryui.ru/about)
  Dual licensed under the MIT (MIT-LICENSE.txt)
  and GPL (GPL-LICENSE.txt) licenses.
 
 
-->
<!doctype html>
<html lang="en">
<head>
  <title>jQuery UI Resizable - Visual feedback</title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <style type="text/css">
  #resizable { width: 150px; height: 150px; padding: 0.5em; }
  #resizable h3 { text-align: center; margin: 0; }
  .ui-resizable-ghost { border: 1px dotted gray; }
  </style>
  <script type="text/javascript">
  $(function() {
    $("#resizable").resizable({
      ghost: true
    });
  });
  </script>
</head>
<body>
<div class="demo">
  
<div id="resizable" class="ui-widget-content">
  <h3 class="ui-widget-header">Ghost</h3>
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>Instead of showing the actual element during resize, set the <code>ghost</code> option to true to show a semi-transparent part of the element.</p>
</div><!-- End demo-description -->
</body>
</html>



Set max Width, max Height, min width and min height

 
<html lang="en">
<head>
  <title></title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.resizable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <script type="text/javascript">
    $(function() {
        var resizeOpts = {
          maxWidth: 500,
          maxHeight: 500,
          minWidth: 100,
          minHeight: 100
        }
        $(".resize").resizable(resizeOpts);
    });
  </script>
</head>
<body>
    <div class="resize">
      <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse auctor ligula vel odio. Nam et sem vitae nibh convallis euismod. Aenean vitae urna quis augue adipiscing hendrerit. Nam faucibus. Phasellus eros. Ut bibendum eros at nibh. Sed erat. Aenean id enim vitae leo aliquet rutrum. Mauris fringilla euismod orci. Morbi tempus purus eget felis. Sed dui eros, tempor id, iaculis vel, pretium eget, nunc. Pellentesque vehicula tincidunt arcu. Ut a velit. In dapibus, lacus vitae lobortis dictum, libero pede venenatis magna, eu sagittis nunc erat sed ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus est dolor, mollis congue, ullamcorper eu, auctor ut, augue.</div>
    </div>
</body>
</html>