jQuery UI 例 -リサイズ(Resizable)
マウスを使用して要素のサイズを変更します。
resizable インタラクションの詳細については、API ドキュメントを参照してください。リサイズ可能ウィジェット(Resizable Widget)。
デフォルト機能
任意の DOM 要素でリサイズ機能を有効にします。マウスで右側または下側の境界線を目的の幅または高さまでドラッグします。
<!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>
アニメーション
使用animateオプション(ブール値)は、リサイズ動作をアニメーション化します。このオプションを true に設定すると、ドラッグ中に輪郭を目的の位置までドラッグし、ドラッグを停止したときに要素がアニメーションでそのサイズに調整されます。
<!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>
リサイズ領域の制限
リサイズ領域の境界を定義します。使用containmentオプションで、親の DOM 要素または jQuery セレクター(例: '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>
遅延開始
によってdelayオプションで、リサイズ開始の遅延をミリ秒単位で設定します。によってdistanceオプションで、カーソルが押されて指定されたピクセル数だけドラッグされた後にのみ、リサイズを許可します。
<!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>
ヘルパー
を設定することでhelperオプションに CSS クラスを指定すると、リサイズ中は要素の輪郭だけが表示されます。
<!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>
最大/最小サイズ
使用maxHeight、maxWidth、minHeightとminWidthオプションで、リサイズ可能な要素の最大/最小の高さまたは幅を制限します。
<!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>
縦横比の保持
既存の縦横比を維持するか、新しい縦横比を設定してリサイズの比率を制限します。設定aspectRatioオプションを true に設定し、必要に応じて新しい比率(例: 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>
グリッドにスナップ
リサイズ可能な要素をグリッドに揃えます。によってgridオプションで、グリッドセルのサイズ(ピクセル単位の高さと幅)を設定します。
<!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>
同期リサイズ
要素の辺をクリックしてドラッグすることで、複数の要素のサイズを同時に調整します。にalsoResizeオプションに共有セレクターを渡します。
<!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>
テキストボックス
リサイズ可能なテキストボックス。
<!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>
視覚的フィードバック
を設定することでghostオプションを true に設定すると、実際の要素の代わりに、リサイズ中は半透明の要素が表示されます。
<!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>
その他の拡張