Ejemplos de jQuery UI -Redimensionar (Resizable)
Usa el ratón para cambiar el tamaño de un elemento.
Si deseas obtener más detalles sobre la interacción resizable, consulta la documentación de la API.Widget redimensionable (Resizable Widget)。
Funcionalidad por defecto
Habilita la funcionalidad resizable en cualquier elemento DOM. Arrastra el borde derecho o inferior con el ratón hasta el ancho o alto deseado.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 默认功能</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#resizable { width: 150px; height: 150px; padding: 0.5em; }
#resizable h3 { text-align: center; margin: 0; }
</style>
<script>
$(function() {
$( "#resizable" ).resizable();
});
</script>
</head>
<body>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">缩放(Resizable)</h3>
</div>
</body>
</html>
Animación
Usaanimatela opción (booleano) para animar el comportamiento de redimensionamiento. Cuando la opción se establece en true, arrastra el contorno hasta la posición deseada y el elemento se ajustará a ese tamaño con una animación cuando se detenga el arrastre.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 动画</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#resizable { width: 150px; height: 150px; padding: 0.5em; }
#resizable h3 { text-align: center; margin: 0; }
.ui-resizable-helper { border: 1px dotted gray; }
</style>
<script>
$(function() {
$( "#resizable" ).resizable({
animate: true
});
});
</script>
</head>
<body>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">动画</h3>
</div>
</body>
</html>
Limitar el área de redimensionamiento
Define los límites del área de redimensionamiento. Usacontainmentla opción para especificar un elemento DOM padre o un selector de jQuery, como 'document.'.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 限制缩放区域</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#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>
$(function() {
$( "#resizable" ).resizable({
containment: "#container"
});
});
</script>
</head>
<body>
<div id="container" class="ui-widget-content">
<h3 class="ui-widget-header">限制</h3>
<div id="resizable" class="ui-state-active">
<h3 class="ui-widget-header">缩放(Resizable)</h3>
</div>
</div>
</body>
</html>
Inicio con retraso
Condelayla opción se establece el número de milisegundos para retrasar el inicio del redimensionamiento. Condistancela opción se habilita el redimensionamiento solo después de que el cursor se presione y se arrastre una cantidad específica de píxeles.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 延迟开始</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#resizable, #resizable2 { width: 150px; height: 150px; padding: 0.5em; }
#resizable h3, #resizable2 h3 { text-align: center; margin: 0; }
</style>
<script>
$(function() {
$( "#resizable" ).resizable({
delay: 1000
});
$( "#resizable2" ).resizable({
distance: 40
});
});
</script>
</head>
<body>
<h3 class="docs">时间延迟 (ms):</h3>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">时间</h3>
</div>
<h3 class="docs">距离延迟 (px):</h3>
<div id="resizable2" class="ui-widget-content">
<h3 class="ui-widget-header">距离</h3>
</div>
</body>
</html>
Ayudante
Al establecerhelperla opción como una clase CSS, solo se muestra el contorno del elemento al redimensionar.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 助手</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#resizable { width: 150px; height: 150px; padding: 0.5em; }
#resizable h3 { text-align: center; margin: 0; }
.ui-resizable-helper { border: 2px dotted #00F; }
</style>
<script>
$(function() {
$( "#resizable" ).resizable({
helper: "ui-resizable-helper"
});
});
</script>
</head>
<body>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">助手</h3>
</div>
</body>
</html>
Tamaño máximo/mínimo
UsamaxHeight、maxWidth、minHeightyminWidthla opción para limitar la altura o el ancho máximo o mínimo del elemento redimensionable.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 最大/最小尺寸</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#resizable { width: 200px; height: 150px; padding: 5px; }
#resizable h3 { text-align: center; margin: 0; }
</style>
<script>
$(function() {
$( "#resizable" ).resizable({
maxHeight: 250,
maxWidth: 350,
minHeight: 150,
minWidth: 200
});
});
</script>
</head>
<body>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">放大/缩小</h3>
</div>
</body>
</html>
Mantener la relación de aspecto
Mantén la relación de aspecto existente o establece una nueva para limitar la escala. EstableceaspectRatiola opción como true y, opcionalmente, pasa una nueva proporción (por ejemplo, 4/3).
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 保持纵横比</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#resizable { width: 160px; height: 90px; padding: 0.5em; }
#resizable h3 { text-align: center; margin: 0; }
</style>
<script>
$(function() {
$( "#resizable" ).resizable({
aspectRatio: 16 / 9
});
});
</script>
</head>
<body>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">保持纵横比</h3>
</div>
</body>
</html>
Alinear a la cuadrícula
Alinea los elementos redimensionables a la cuadrícula. Congridla opción se establece el tamaño de las celdas de la cuadrícula (alto y ancho en píxeles).
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 对齐到网格</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#resizable { width: 150px; height: 150px; padding: 0.5em; }
#resizable h3 { text-align: center; margin: 0; }
</style>
<script>
$(function() {
$( "#resizable" ).resizable({
grid: 50
});
});
</script>
</head>
<body>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">网格</h3>
</div>
</body>
</html>
Redimensionamiento sincronizado
Haz clic y arrastra el borde de un elemento para redimensionar varios elementos a la vez. Proporciona aalsoResizela opción un selector compartido.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 同步缩放</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#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>
$(function() {
$( "#resizable" ).resizable({
alsoResize: "#also"
});
$( "#also" ).resizable();
});
</script>
</head>
<body>
<div id="resizable" class="ui-widget-header">
<h3 class="ui-state-active">缩放</h3>
</div>
<div id="also" class="ui-widget-content">
<h3 class="ui-widget-header">同步缩放</h3>
</div>
</body>
</html>
Cuadro de texto
Cuadro de texto redimensionable.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 文本框</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
.ui-resizable-se {
bottom: 17px;
}
</style>
<script>
$(function() {
$( "#resizable" ).resizable({
handles: "se"
});
});
</script>
</head>
<body>
<textarea id="resizable" rows="5" cols="20"></textarea>
</body>
</html>
Retroalimentación visual
Al establecerghostla opción como true, se muestra un elemento semitransparente durante el redimensionamiento en lugar de un elemento real.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 缩放(Resizable) - 视觉反馈</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
#resizable { width: 150px; height: 150px; padding: 0.5em; }
#resizable h3 { text-align: center; margin: 0; }
.ui-resizable-ghost { border: 1px dotted gray; }
</style>
<script>
$(function() {
$( "#resizable" ).resizable({
ghost: true
});
});
</script>
</head>
<body>
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">Ghost</h3>
</div>
</body>
</html>
Otras extensiones