javascriptdrag-and-dropdojoresizemovable

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.

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

});

`


Solution

  • This can be achieved by using the dojo ResizeHandler , so the setps to use it are :

    1. import the dojox/layout/ResizeHandle

    2. Import the resize hander Css Style ( for rendering and resize icon )

    3. set your resizable div poristion to relative

    4. instantiate the rsizeHandler and set target to your div id

    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>