DOJO Resizing a div

时间:2017-06-15 10:00:03

标签: javascript drag-and-drop dojo resize movable

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.

Thanks in Advance.

Javascript code :

require(["dojo/dnd/Moveable", "dojo/dom", "dojo/on", "dojo/domReady!"],
  function(Moveable, dom, on){

    var dnd = new Moveable(dom.byId("panelContent"));

});

`

2 个答案:

答案 0 :(得分:1)

在以下示例中,您可以看到如何启动dijit/layout/ContentPane并以编程方式调整大小(按下按钮)。

基本上你需要:

  • 使用ContentPane
  • 检索您的registry.byId()
  • 使用dojo setter ContentPane;
  • 更改.set('propertyName', yourValue)的样式属性



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();

});
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

这可以通过使用dojo ResizeHandler来实现,因此使用它的setps是:

  1. 导入dojox/layout/ResizeHandle

  2. 导入resize hander Css Style(用于渲染和调整图标大小)

  3. 将您的可调整大小的div portion设置为relative

  4. 实例化rsizeHandler并将target设置为div id
  5. 所以实例化就像:

    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>