DOJO 调整 div
DOJO Resizing a div
我有一个 ID 为 "panelContent" 的 div,我想调整 div 的大小,我当前的 dojo 程序可以移动一个 div 我也想调整它的大小, 谁能帮帮我。
提前致谢。
Javascript 代码:
require(["dojo/dnd/Moveable", "dojo/dom", "dojo/on", "dojo/domReady!"],
function(Moveable, dom, on){
var dnd = new Moveable(dom.byId("panelContent"));
});
`
在下面的示例中,您可以看到如何启动 dijit/layout/ContentPane
并以编程方式调整它的大小(在单击按钮时)。
基本上你需要:
- 使用
registry.byId()
检索您的 ContentPane
。
- 使用 dojo setter
.set('propertyName', yourValue)
; 为 ContentPane
更改样式 属性
require(["dijit/layout/ContentPane", "dijit/registry", "dijit/form/Button", "dojo/domReady!"], function(ContentPane, registry, Button) {
new ContentPane({
content: "<p>Optionally set new content now</p>",
style: "width: 150px; height:150px; background-color:yellow;"
}, "panelContent").startup();
var myButton = new Button({
label: "Click me to enlarge the panel!",
onClick: function() {
registry.byId("panelContent").set('style','width: 350px; background-color:red;')
}
}, "button").startup();
});
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dijit/themes/claro/claro.css" />
<script>
window.dojoConfig = {
parseOnLoad: false,
async: true
};
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.1/dojo/dojo.js">
</script>
<body class="claro">
<div id="panelContent" data-dojo-type="dijit/layout/ContentPane">
Hi, pretty boring huh?
</div>
<button id="button" type="button"></button>
</body>
这可以通过使用 dojo ResizeHandler 来实现,因此使用它的设置是:
导入dojox/layout/ResizeHandle
导入调整大小处理程序Css Style(用于渲染和调整图标大小)
将可调整大小的 div 位置设置为相对
- 实例化 rsizeHandler 并将目标设置为您的 div id
所以实例化就像:
var handle = new ResizeHandle({
targetId:"panelContent"
}).placeAt("panelContent");
您可以在下面找到一个有效的片段
require([
"dojox/layout/ResizeHandle",
"dojo/dnd/move",
'dojo/dom',
'dojo/domReady!'
], function(ResizeHandle, dojoDnd, Dom) {
new dojoDnd.parentConstrainedMoveable(Dom.byId("panelContent"), {
handle: this.focusNode,
area: "content",
within: true
})
var handle = new ResizeHandle({
targetId:"panelContent"
}).placeAt("panelContent");
});
#panelContent {
background-color:green;
position:relative;
width:200px;
height:100px;
cursor:pointer;
}
body,html,#container {
width:100%;
height:100%;
}
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojox/layout/resources/ResizeHandle.css" rel="stylesheet"/>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dijit/themes/claro/claro.css" />
<script>
window.dojoConfig = {
parseOnLoad: false,
async: true
};
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js"></script>
<div id="container" class="claro">
<div id="panelContent">
<div id="handler"></div>
</div>
</div>
我有一个 ID 为 "panelContent" 的 div,我想调整 div 的大小,我当前的 dojo 程序可以移动一个 div 我也想调整它的大小, 谁能帮帮我。
提前致谢。
Javascript 代码:
require(["dojo/dnd/Moveable", "dojo/dom", "dojo/on", "dojo/domReady!"],
function(Moveable, dom, on){
var dnd = new Moveable(dom.byId("panelContent"));
});
`
在下面的示例中,您可以看到如何启动 dijit/layout/ContentPane
并以编程方式调整它的大小(在单击按钮时)。
基本上你需要:
- 使用
registry.byId()
检索您的ContentPane
。 - 使用 dojo setter
.set('propertyName', yourValue)
; 为
ContentPane
更改样式 属性
require(["dijit/layout/ContentPane", "dijit/registry", "dijit/form/Button", "dojo/domReady!"], function(ContentPane, registry, Button) {
new ContentPane({
content: "<p>Optionally set new content now</p>",
style: "width: 150px; height:150px; background-color:yellow;"
}, "panelContent").startup();
var myButton = new Button({
label: "Click me to enlarge the panel!",
onClick: function() {
registry.byId("panelContent").set('style','width: 350px; background-color:red;')
}
}, "button").startup();
});
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dijit/themes/claro/claro.css" />
<script>
window.dojoConfig = {
parseOnLoad: false,
async: true
};
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.1/dojo/dojo.js">
</script>
<body class="claro">
<div id="panelContent" data-dojo-type="dijit/layout/ContentPane">
Hi, pretty boring huh?
</div>
<button id="button" type="button"></button>
</body>
这可以通过使用 dojo ResizeHandler 来实现,因此使用它的设置是:
导入
dojox/layout/ResizeHandle
导入调整大小处理程序Css Style(用于渲染和调整图标大小)
将可调整大小的 div 位置设置为相对
- 实例化 rsizeHandler 并将目标设置为您的 div id
所以实例化就像:
var handle = new ResizeHandle({
targetId:"panelContent"
}).placeAt("panelContent");
您可以在下面找到一个有效的片段
require([
"dojox/layout/ResizeHandle",
"dojo/dnd/move",
'dojo/dom',
'dojo/domReady!'
], function(ResizeHandle, dojoDnd, Dom) {
new dojoDnd.parentConstrainedMoveable(Dom.byId("panelContent"), {
handle: this.focusNode,
area: "content",
within: true
})
var handle = new ResizeHandle({
targetId:"panelContent"
}).placeAt("panelContent");
});
#panelContent {
background-color:green;
position:relative;
width:200px;
height:100px;
cursor:pointer;
}
body,html,#container {
width:100%;
height:100%;
}
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojox/layout/resources/ResizeHandle.css" rel="stylesheet"/>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dijit/themes/claro/claro.css" />
<script>
window.dojoConfig = {
parseOnLoad: false,
async: true
};
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js"></script>
<div id="container" class="claro">
<div id="panelContent">
<div id="handler"></div>
</div>
</div>