Resizable Widget | jQuery UI API Documentation (original) (raw)

Description: Change the size of an element using the mouse.

QuickNavExamples

Options

Methods

Events

The jQuery UI Resizable plugin makes selected elements resizable (meaning they have draggable resize handles). You can specify one or more handles as well as min and max width and height.

Theming

The resizable widget uses the jQuery UI CSS framework to style its look and feel. If resizable specific styling is needed, the following CSS class names can be used for overrides or as keys for the classes option:

Dependencies

Additional Notes:

Options

alsoResize

Default: false

One or more elements to resize synchronously with the resizable element.

Code examples:

Initialize the resizable with the alsoResize option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the alsoResize option, after initialization:

1 2 3 4 5 var alsoResize = (".selector").resizable("option","alsoResize");( ".selector" ).resizable( "option", "alsoResize" );(".selector").resizable("option","alsoResize");( ".selector" ).resizable( "option", "alsoResize", "#mirror" );

animate

Default: false

Animates to the final size after resizing.

Code examples:

Initialize the resizable with the animate option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the animate option, after initialization:

1 2 3 4 5 var animate = (".selector").resizable("option","animate");( ".selector" ).resizable( "option", "animate" );(".selector").resizable("option","animate");( ".selector" ).resizable( "option", "animate", true );

animateDuration

Default: "slow"

How long to animate when using the animate option.

Multiple types supported:

Code examples:

Initialize the resizable with the animateDuration option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the animateDuration option, after initialization:

1 2 3 4 5 var animateDuration = (".selector").resizable("option","animateDuration");( ".selector" ).resizable( "option", "animateDuration" );(".selector").resizable("option","animateDuration");( ".selector" ).resizable( "option", "animateDuration", "fast" );

animateEasing

Default: "swing"

Which easing to apply when using the animate option.

Code examples:

Initialize the resizable with the animateEasing option specified:

1 2 3 $( ".selector" ).resizable({ animateEasing: "easeOutBounce"

Get or set the animateEasing option, after initialization:

1 2 3 4 5 var animateEasing = (".selector").resizable("option","animateEasing");( ".selector" ).resizable( "option", "animateEasing" );(".selector").resizable("option","animateEasing");( ".selector" ).resizable( "option", "animateEasing", "easeOutBounce" );

aspectRatio

Default: false

Whether the element should be constrained to a specific aspect ratio.

Multiple types supported:

Code examples:

Initialize the resizable with the aspectRatio option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the aspectRatio option, after initialization:

1 2 3 4 5 var aspectRatio = (".selector").resizable("option","aspectRatio");( ".selector" ).resizable( "option", "aspectRatio" );(".selector").resizable("option","aspectRatio");( ".selector" ).resizable( "option", "aspectRatio", true );

autoHide

Default: false

Whether the handles should hide when the user is not hovering over the element.

Code examples:

Initialize the resizable with the autoHide option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the autoHide option, after initialization:

1 2 3 4 5 var autoHide = (".selector").resizable("option","autoHide");( ".selector" ).resizable( "option", "autoHide" );(".selector").resizable("option","autoHide");( ".selector" ).resizable( "option", "autoHide", true );

cancel

Default: "input,textarea,button,select,option"

Prevents resizing from starting on specified elements.

Code examples:

Initialize the resizable with the cancel option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the cancel option, after initialization:

1 2 3 4 5 var cancel = (".selector").resizable("option","cancel");( ".selector" ).resizable( "option", "cancel" );(".selector").resizable("option","cancel");( ".selector" ).resizable( "option", "cancel", ".cancel" );

classes

Default:

"ui-resizable-se": "ui-icon ui-icon-gripsmall-diagonal-se"

Specify additional classes to add to the widget's elements. Any of classes specified in the Theming section can be used as keys to override their value. To learn more about this option, check out the learn article about the classes option.

Code examples:

Initialize the resizable with the classes option specified, changing the theming for the ui-resizable class:

1 2 3 4 5 $( ".selector" ).resizable({ "ui-resizable": "highlight"

Get or set a property of the classes option, after initialization, here reading and changing the theming for the ui-resizable class:

1 2 3 4 5 var themeClass = (".selector").resizable("option","classes.ui−resizable");( ".selector" ).resizable( "option", "classes.ui-resizable" );(".selector").resizable("option","classes.uiresizable");( ".selector" ).resizable( "option", "classes.ui-resizable", "highlight" );

containment

Default: false

Constrains resizing to within the bounds of the specified element or region.

Multiple types supported:

Code examples:

Initialize the resizable with the containment option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the containment option, after initialization:

1 2 3 4 5 var containment = (".selector").resizable("option","containment");( ".selector" ).resizable( "option", "containment" );(".selector").resizable("option","containment");( ".selector" ).resizable( "option", "containment", "parent" );

delay

Default: 0

Tolerance, in milliseconds, for when resizing should start. If specified, resizing will not start until after mouse is moved beyond duration. This can help prevent unintended resizing when clicking on an element. (version deprecated: 1.12)

Code examples:

Initialize the resizable with the delay option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the delay option, after initialization:

1 2 3 4 5 var delay = (".selector").resizable("option","delay");( ".selector" ).resizable( "option", "delay" );(".selector").resizable("option","delay");( ".selector" ).resizable( "option", "delay", 150 );

disabled

Default: false

Disables the resizable if set to true.

Code examples:

Initialize the resizable with the disabled option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the disabled option, after initialization:

1 2 3 4 5 var disabled = (".selector").resizable("option","disabled");( ".selector" ).resizable( "option", "disabled" );(".selector").resizable("option","disabled");( ".selector" ).resizable( "option", "disabled", true );

distance

Default: 1

Tolerance, in pixels, for when resizing should start. If specified, resizing will not start until after mouse is moved beyond distance. This can help prevent unintended resizing when clicking on an element. (version deprecated: 1.12)

Code examples:

Initialize the resizable with the distance option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the distance option, after initialization:

1 2 3 4 5 var distance = (".selector").resizable("option","distance");( ".selector" ).resizable( "option", "distance" );(".selector").resizable("option","distance");( ".selector" ).resizable( "option", "distance", 30 );

ghost

Default: false

If set to true, a semi-transparent helper element is shown for resizing.

Code examples:

Initialize the resizable with the ghost option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the ghost option, after initialization:

1 2 3 4 5 var ghost = (".selector").resizable("option","ghost");( ".selector" ).resizable( "option", "ghost" );(".selector").resizable("option","ghost");( ".selector" ).resizable( "option", "ghost", true );

grid

Default: false

Snaps the resizing element to a grid, every x and y pixels. Array values: [ x, y ].

Code examples:

Initialize the resizable with the grid option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the grid option, after initialization:

1 2 3 4 5 var grid = (".selector").resizable("option","grid");( ".selector" ).resizable( "option", "grid" );(".selector").resizable("option","grid");( ".selector" ).resizable( "option", "grid", [ 20, 10 ] );

handles

Default: "e, s, se"

Which handles can be used for resizing.

Multiple types supported:

Code examples:

Initialize the resizable with the handles option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the handles option, after initialization:

1 2 3 4 5 var handles = (".selector").resizable("option","handles");( ".selector" ).resizable( "option", "handles" );(".selector").resizable("option","handles");( ".selector" ).resizable( "option", "handles", "n, e, s, w" );

helper

Default: false

A class name that will be added to a proxy element to outline the resize during the drag of the resize handle. Once the resize is complete, the original element is sized.

Code examples:

Initialize the resizable with the helper option specified:

1 2 3 $( ".selector" ).resizable({ helper: "resizable-helper"

Get or set the helper option, after initialization:

1 2 3 4 5 var helper = (".selector").resizable("option","helper");( ".selector" ).resizable( "option", "helper" );(".selector").resizable("option","helper");( ".selector" ).resizable( "option", "helper", "resizable-helper" );

maxHeight

Default: null

The maximum height the resizable should be allowed to resize to.

Code examples:

Initialize the resizable with the maxHeight option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the maxHeight option, after initialization:

1 2 3 4 5 var maxHeight = (".selector").resizable("option","maxHeight");( ".selector" ).resizable( "option", "maxHeight" );(".selector").resizable("option","maxHeight");( ".selector" ).resizable( "option", "maxHeight", 300 );

maxWidth

Default: null

The maximum width the resizable should be allowed to resize to.

Code examples:

Initialize the resizable with the maxWidth option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the maxWidth option, after initialization:

1 2 3 4 5 var maxWidth = (".selector").resizable("option","maxWidth");( ".selector" ).resizable( "option", "maxWidth" );(".selector").resizable("option","maxWidth");( ".selector" ).resizable( "option", "maxWidth", 300 );

minHeight

Default: 10

The minimum height the resizable should be allowed to resize to.

Code examples:

Initialize the resizable with the minHeight option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the minHeight option, after initialization:

1 2 3 4 5 var minHeight = (".selector").resizable("option","minHeight");( ".selector" ).resizable( "option", "minHeight" );(".selector").resizable("option","minHeight");( ".selector" ).resizable( "option", "minHeight", 150 );

minWidth

Default: 10

The minimum width the resizable should be allowed to resize to.

Code examples:

Initialize the resizable with the minWidth option specified:

1 2 3 $( ".selector" ).resizable({

Get or set the minWidth option, after initialization:

1 2 3 4 5 var minWidth = (".selector").resizable("option","minWidth");( ".selector" ).resizable( "option", "minWidth" );(".selector").resizable("option","minWidth");( ".selector" ).resizable( "option", "minWidth", 150 );

Methods

destroy()Returns: jQuery (plugin only)

Removes the resizable functionality completely. This will return the element back to its pre-init state.

Code examples:

Invoke the destroy method:

1 $( ".selector" ).resizable( "destroy" );

disable()Returns: jQuery (plugin only)

Disables the resizable.

Code examples:

Invoke the disable method:

1 $( ".selector" ).resizable( "disable" );

enable()Returns: jQuery (plugin only)

Enables the resizable.

Code examples:

Invoke the enable method:

1 $( ".selector" ).resizable( "enable" );

instance()Returns: Object

Retrieves the resizable's instance object. If the element does not have an associated instance, undefined is returned.

Unlike other widget methods, instance() is safe to call on any element after the resizable plugin has loaded.

Code examples:

Invoke the instance method:

1 $( ".selector" ).resizable( "instance" );

option( optionName )Returns: Object

Gets the value currently associated with the specified optionName.

Note: For options that have objects as their value, you can get the value of a specific key by using dot notation. For example, "foo.bar" would get the value of the bar property on the foo option.

Code examples:

Invoke the method:

1 var isDisabled = $( ".selector" ).resizable( "option", "disabled" );

option()Returns: PlainObject

Gets an object containing key/value pairs representing the current resizable options hash.

Code examples:

Invoke the method:

1 var options = $( ".selector" ).resizable( "option" );

option( optionName, value )Returns: jQuery (plugin only)

Sets the value of the resizable option associated with the specified optionName.

Note: For options that have objects as their value, you can set the value of just one property by using dot notation for optionName. For example, "foo.bar" would update only the bar property of the foo option.

Code examples:

Invoke the method:

1 $( ".selector" ).resizable( "option", "disabled", true );

option( options )Returns: jQuery (plugin only)

Sets one or more options for the resizable.

Code examples:

Invoke the method:

1 $( ".selector" ).resizable( "option", { disabled: true } );

Events

create( event, ui )Type: resizecreate

Triggered when the resizable is created.

Note: The ui object is empty but included for consistency with other events.

Code examples:

Initialize the resizable with the create callback specified:

1 2 3 $( ".selector" ).resizable({ create: function( event, ui ) {}

Bind an event listener to the resizecreate event:

1 $( ".selector" ).on( "resizecreate", function( event, ui ) {} );

resize( event, ui )Type: resize

This event is triggered during the resize, on the drag of the resize handler.

Code examples:

Initialize the resizable with the resize callback specified:

1 2 3 $( ".selector" ).resizable({ resize: function( event, ui ) {}

Bind an event listener to the resize event:

1 $( ".selector" ).on( "resize", function( event, ui ) {} );

Restrict height resizing to 30 pixel increments:

1 2 3 4 5 $( ".selector" ).resizable({ resize: function( event, ui ) { ui.size.height = Math.round( ui.size.height / 30 ) * 30;

start( event, ui )Type: resizestart

This event is triggered at the start of a resize operation.

Code examples:

Initialize the resizable with the start callback specified:

1 2 3 $( ".selector" ).resizable({ start: function( event, ui ) {}

Bind an event listener to the resizestart event:

1 $( ".selector" ).on( "resizestart", function( event, ui ) {} );

stop( event, ui )Type: resizestop

This event is triggered at the end of a resize operation.

Code examples:

Initialize the resizable with the stop callback specified:

1 2 3 $( ".selector" ).resizable({ stop: function( event, ui ) {}

Bind an event listener to the resizestop event:

1 $( ".selector" ).on( "resizestop", function( event, ui ) {} );

Example:

A simple jQuery UI Resizable.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <title>resizable demo</title> <link rel="stylesheet" href="" title="undefined" rel="noopener noreferrer">https://code.jquery.com/ui/1.13.3/themes/smoothness/jquery-ui.css"\> <script src="" title="undefined" rel="noopener noreferrer">https://code.jquery.com/jquery-3.7.1.js"\></script> <script src="" title="undefined" rel="noopener noreferrer">https://code.jquery.com/ui/1.13.3/jquery-ui.js"\></script><div id="resizable"></div>$( "#resizable" ).resizable();

Demo: