Saturday, September 21, 2019

jQuery UI resizable

jQuery UI resizable() method is used to resize any DOM element. It simplifies the method of resizing of elements and reduces time and a lot of coding.


The resizable () method displays an icon in the bottom right of the item to resize.
Syntax:

You can use the resizable () method in two forms:

  1. $(selector, context).resizable (options) Method  
  1. $(selector, context).resizable ("action", params) Method  

First Method

The resizable (options) method specifies that you can resize an HTML element. Here the ?options? parameter is an object that specifies the behavior of the elements involved when resizing.

Syntax:
  1. $(selector, context).resizable (options);  
You can use one or more options at a time of using JavaScript object. In the case of more than one option, you have to separate them using a comma as follows:
  1. $(selector, context).resizable ({option1: value1, option2: value2..... });  
Following is a list of different options that can be used with this method:
OptionDescription
alsoResizeThis option is of type selector, jQuery , or any DOM element. It represents elements that also resize when resizing the original object. By default its value is FALSE.
animateIf you set this option to TRUE, it enables a visual effect during resizing when the mouse button is released. The default value is FALSE (no effect).
animateDurationThis option specifies the duration of the resizing effect in millisecond. It is used only when animate option is true. By default its value is "slow".
animateEasingThis option specifies which easing should be applied when using the animate option. By default its value is "swing".
aspectRatioThis option indicates the aspect (height and width) ratio for the item. By default its value is false.
autoHideThis option is used to hide the magnification icon or handles, except when the mouse is over the item. By default its value is false.
cancelThis option is used to prevent resizing on specified elements. By default its value is input, textarea, button, select, option.
containmentThis option is used restrict the resizing of elements within a specified element or region. By default its value is false.
delayThis option is used to set tolerance or delay in milliseconds. After that, resizing or displacement will begin. By default its value is 0.
disabledIf you set this option to TRUE, it disables the resizing mechanism. The mouse no longer resizes elements, until the mechanism is enabled, using the resizable ("enable"). By default its value is false.
distanceThis option specifies that the resizing will start only when the mouse moves a distance(pixels). By default its value is 1 pixel. This can help prevent unintended resizing when clicking on an element.
ghostIf you set this option to TRUE, a semi-transparent helper element is shown for resizing. This ghost item will be deleted when the mouse is released. By default its value is false.
gridThis option is of type array [x, y], indicating the number of pixels that the element expands horizontally and vertically during movement of the mouse. By default its value is false.
handlesThis option is a character string that specifies which sides or angles of the element can be resized. By default its values are e, s, se.
helperThis option is used to add a CSS class to style the element which you want to resize. When the element is resized a new <div> element is created, which is the one that is scaled (UI-resizable-helper class). Once the resize is complete, the original element is sized and the <div> element disappears. By default its value is false.
maxHeightThis option is used to set the maximum height the resizable should be allowed to resize to. By default its value is NULL.
maxWidthThis option is used to set the maximum width the resizable should be allowed to resize to. By default its value is NULL.
minHeightThis option is used to set the minimum height the resizable should be allowed to resize to. By default its value is 10.
minWidthThis option is used to set the minimum width the resizable should be allowed to resize to. By default its value is 10.

jQueryUI resizable() Example 1

Let's take a simple example to demonstrate the resizable functionality, passing no parameter to the resizable () method.

  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Resizable functionality</title>  
  6.       <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">  
  7.       <script src="http://code.jquery.com/jquery-1.10.2.js"></script>  
  8.       <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>  
  9.       <!-- CSS -->  
  10.       <style>  
  11.          .ui-widget-header {  
  12.             background:lightyellow;  
  13.             border: 1px solid #b9cd6d;  
  14.             color: Red;  
  15.             font-weight: bold;  
  16.          }  
  17.          .ui-widget-content {  
  18.             background: lightgreen;  
  19.             border: 1px solid #DDDDDD;  
  20.             color: Red;  
  21.          }  
  22.          #resizable { width: 150px; height: 150px; padding: 0.5em;  
  23.             text-align: center; margin: 0; }  
  24.       </style>  
  25.       <!-- Javascript -->  
  26.       <script>  
  27.          $(function() {  
  28.             $( "#resizable" ).resizable();  
  29.          });  
  30.       </script>  
  31.    </head>  
  32.   
  33.    <body>  
  34.       <!-- HTML -->   
  35.       <div id="resizable" class="ui-widget-content">   
  36.          <h3 class="ui-widget-header">Pull my edges to resize me!!</h3>  
  37.       </div>  
  38.   </body>  
  39. </html>  

jQueryUI resizable() example 2

Use of animate and ghost:
The following example shows the usage of two options animate and ghost in the resize function of jQuery UI.

  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Resizable functionality</title>  
  6.       <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">  
  7.       <script src="http://code.jquery.com/jquery-1.10.2.js"></script>  
  8.       <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>  
  9.       <!-- CSS -->  
  10.       <style>  
  11.          .ui-widget-header {  
  12.             background:lightyellow;  
  13.             border: 1px solid #b9cd6d;  
  14.             color: Red;  
  15.             font-weight: bold;  
  16.          }  
  17.          .ui-widget-content {  
  18.             background: lightgreen;  
  19.             border: 1px solid #DDDDDD;  
  20.             color: Red;  
  21.          }  
  22.          #resizable-2,#resizable-3 {   
  23.             width: 150px; height: 150px; padding: 0.5em;  
  24.             text-align: center; margin: 0; }  
  25.       </style>  
  26.       <!-- JavaScript -->  
  27.       <script>  
  28.          $(function() {  
  29.             $( "#resizable-2" ).resizable({  
  30.                animate: true  
  31.             });  
  32.             $( "#resizable-3" ).resizable({  
  33.                ghost: true  
  34.             });  
  35.          });  
  36.       </script>  
  37.    </head>  
  38.    <body>  
  39.       <!-- HTML -->   
  40.       <div id="resizable-2" class="ui-widget-content">   
  41.          <h3 class="ui-widget-header">  
  42.             Pull my edges and Check the animation!!  
  43.          </h3>  
  44.       </div><br>  
  45.       <div id="resizable-3" class="ui-widget-content">   
  46.          <h3 class="ui-widget-header">I'm ghost!!</h3>  
  47.       </div>   
  48.    </body>  
  49. </html>  

jQuery UI resizable() example 3

Use of delay, distance and autoHide:
The following example shows the usage of three options delay, distance and autoHide in the resize function of jQuery UI.

  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Resizable functionality</title>  
  6.       <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">  
  7.       <script src="http://code.jquery.com/jquery-1.10.2.js"></script>  
  8.       <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>  
  9.       <style>  
  10.          .ui-widget-header {  
  11.             background:lightgreen;  
  12.             border: 1px solid #b9cd6d;  
  13.             color: red;  
  14.             font-weight: bold;  
  15.          }  
  16.          .ui-widget-content {  
  17.             background: lightgreen;  
  18.             border: 1px solid #DDDDDD;  
  19.             color: black;  
  20.          }  
  21.          .square {  
  22.             width: 150px;  
  23.             height: 150px;  
  24.             border: 1px solid black;  
  25.             text-align: center;  
  26.             float: left;  
  27.             margin-left: 20px;  
  28.             -right: 20px;  
  29.          }  
  30.       </style>  
  31.       <script>  
  32.          $(function() {  
  33.             $( "#resizable-5" ).resizable({  
  34.                delay: 1000  
  35.             });  
  36.   
  37.             $( "#resizable-6" ).resizable({  
  38.                distance: 40  
  39.             });  
  40.             $( "#resizable-7" ).resizable({  
  41.                autoHide: true  
  42.             });  
  43.          });  
  44.       </script>  
  45.    </head>  
  46.    <body>  
  47.       <div id="resizable-5" class="square ui-widget-content">  
  48.          <h3 class="ui-widget-header">  
  49.             Resize starts after delay of 1000ms  
  50.          </h3>  
  51.       </div><br>  
  52.       <div id="resizable-6" class="square ui-widget-content">  
  53.          <h3 class="ui-widget-header">  
  54.             Resize starts at distance of 40px  
  55.          </h3>  
  56.       </div><br>  
  57.       <div id="resizable-7" class="square ui-widget-content">  
  58.          <h3 class="ui-widget-header">  
  59.             Hover over me to see the magnification icon!  
  60.          </h3>  
  61.       </div>  
  62.    </body>  
  63. </html>  

jQuery UI resizable() example 4

Use of alsoResize:
The following example demonstrates the use of option alsoResize in the resize function of jQuery UI.

  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Resizable functionality</title>  
  6.       <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">  
  7.       <script src="http://code.jquery.com/jquery-1.10.2.js"></script>  
  8.       <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>  
  9.       <!-- CSS -->  
  10.       <style>  
  11.          .ui-widget-header {  
  12.             background:yellow;  
  13.             border: 1px solid #b9cd6d;  
  14.             color: red;  
  15.             font-weight: bold;  
  16.          }  
  17.          .ui-widget-content {  
  18.             background: lightgreen;  
  19.             border: 1px solid #DDDDDD;  
  20.             color: red;  
  21.          }  
  22.          #resizable-8,#resizable-9{ width: 150px; height: 150px;   
  23.             padding: 0.5em;text-align: center; margin: 0; }  
  24.       </style>  
  25.       <!-- Javascript -->  
  26.       <script>  
  27.          $(function() {  
  28.             $( "#resizable-8" ).resizable({  
  29.                alsoResize: "#resizable-9"  
  30.             });  
  31.             $( "#resizable-9" ).resizable();  
  32.          });  
  33.       </script>  
  34.    </head>  
  35.    <body>  
  36.       <!-- HTML -->   
  37.       <div id="resizable-8" class="ui-widget-content">   
  38.          <h3 class="ui-widget-header">Resize Me!!</h3>  
  39.       </div><br>  
  40.       <div id="resizable-9" class="ui-widget-content">   
  41.          <h3 class="ui-widget-header">I also get resized!!</h3>  
  42.       </div>   
  43.    </body>  
  44. </html>  

Second Method

The resizable ("action", params) method is used to perform an action on resizable elements. For example: allowing or preventing resizing functionality. The action is specified as a string in the first argument (e.g., "disable" to prevent the resize).
Syntax:
  1. $(selector, context).resizable ("action", params);  
Following is a list of actions that can be used with this method:
ActionDescription
destroyThis action is used to destroy the resizable functionality of an element completely. This will return the element back to its pre-init state.
disableThis action is used to disable the resizing functionality of an element. This method does not accept any arguments.
enableThis action is used to enable the resizing functionality of an element. This method does not accept any arguments.
option( optionName )This action retrieves the value of the specified optionName. This option corresponds to one of those used with resizable (options).
option()This action is used to get an object containing key/value pairs representing the current resizable options hash. This action does not accept any arguments.
option(optionName, value )This action sets the value of the resizable option with the specified optionName. This option corresponds to one of those used with resizable (options).
option( Options )This action sets one or more options for the resizable.
widget()This action returns a jQuery object containing the resizable element. This method does not accept any arguments.

jQueryUI resizable() example 5

Let's take some examples to demonstrate the usage of actions from the above table.
In the following example, we are going to demonstrate the use of destroy () and disable () methods.

  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Resizable functionality</title>  
  6.       <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">  
  7.       <script src="http://code.jquery.com/jquery-1.10.2.js"></script>  
  8.       <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>  
  9.       <!-- CSS -->  
  10.       <style>  
  11.          .ui-widget-header {  
  12.             background:yellow;  
  13.             border: 1px solid #b9cd6d;  
  14.             color: red;  
  15.             font-weight: bold;  
  16.          }  
  17.          .ui-widget-content {  
  18.             background: lightgreen;  
  19.             border: 1px solid #DDDDDD;  
  20.             color: red;  
  21.          }  
  22.          #resizable-12,#resizable-13 { width: 150px; height: 150px;   
  23.             padding: 0.5em;text-align: center; margin: 0; }  
  24.       </style>  
  25.       <!-- Javascript -->  
  26.       <script>  
  27.          $(function() {  
  28.             $( "#resizable-12" ).resizable();  
  29.             $( "#resizable-12" ).resizable('disable');  
  30.             $( "#resizable-13" ).resizable();  
  31.             $( "#resizable-13" ).resizable('destroy');    
  32.          });  
  33.       </script>  
  34.    </head>  
  35.   
  36.    <body>  
  37.       <!-- HTML -->   
  38.       <div id="resizable-12" class="ui-widget-content">   
  39.          <h3 class="ui-widget-header">I'm disable!!</h3>  
  40.       </div><br>  
  41.       <div id="resizable-13" class="ui-widget-content">   
  42.          <h3 class="ui-widget-header">I'm Destroyed!!</h3>  
  43.       </div>  
  44.    </body>  
  45. </html>  

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...