[英]DOJO Resizing a div
I have a div with id "panelContent", I want to resize the div, my current dojo program can move a div i also want to resize it, can anyone help me out. 我有一个ID为“ panelContent”的div,我想调整div的大小,我当前的dojo程序可以移动一个div,我也想调整它的大小,任何人都可以帮助我。
Thanks in Advance. 提前致谢。
Javascript code : JavaScript代码:
require(["dojo/dnd/Moveable", "dojo/dom", "dojo/on", "dojo/domReady!"],
function(Moveable, dom, on){
var dnd = new Moveable(dom.byId("panelContent"));
});
` `
In the following example you can see how you can initiate a dijit/layout/ContentPane
and resize it programmatically (on button click). 在以下示例中,您可以看到如何启动
dijit/layout/ContentPane
并以编程方式调整其大小(单击按钮时)。
Basically you need to: 基本上,您需要:
ContentPane
using registry.byId()
. registry.byId()
检索ContentPane
。 ContentPane
using a dojo setter .set('propertyName', yourValue)
; .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>
This can be achieved by using the dojo ResizeHandler , so the setps to use it are : 这可以通过使用dojo ResizeHandler来实现,因此使用它的setps是:
import the dojox/layout/ResizeHandle
导入
dojox/layout/ResizeHandle
Import the resize hander Css Style ( for rendering and resize icon ) 导入调整大小的Css样式 (用于渲染和调整大小图标)
set your resizable div poristion to relative 将可调整大小的div设置为相对
so the instantiation would be like : 所以实例化就像:
var handle = new ResizeHandle({
targetId:"panelContent"
}).placeAt("panelContent");
you can find bellow a working snippet 您可以在下面找到一个有效的代码段
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.