[英]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
。 .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來實現,因此使用它的setps是:
導入dojox/layout/ResizeHandle
導入調整大小的Css樣式 (用於渲染和調整大小圖標)
將可調整大小的div設置為相對
所以實例化就像:
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.