set div size according to svg in js

0

Good afternoon. Sorry for the beginner doubt, but I wonder if it's possible to use the onresize javascript event to resize a div / container.

I'm using this code:

var resizeTimer;
        window.onresize = function (event) {
            clearTimeout(resizeTimer);
            resizeTimer = setTimeout(function () {
                var s = d3.selectAll('g');
                s = s.remove();
                set_vars();
                drawGraphic();
            }, 100);
        }

but it only resizes the content if I increase / decrease the browser window.

Thanks in advance!

    
asked by anonymous 28.08.2018 / 15:37

3 answers

0

The event onresize is the browser event that is started when you increase and decrease so it only works in these two cases, you need to identify when you want to resize your div, if it is to decrease and increase even this way with JQuery

 window.onresize = $('#id-div').attr('style', 'height:
 ${window.screen.height}')
    
28.08.2018 / 16:00
0

By understanding I want to resize a div.

So to make a div resizable you should use the resize property of CSS.

Example usage:

div{
  border: 1px solid;
  height: 100px;
  resize: both;
  overflow:auto;
}
<div>Teste</div>

The event onresize will not resize your div, it will only call a function (created by you) when the user resizes the div.

So you can use this event only to add another behavior to the div as soon as you start resizing it.

MDM Documentation Web Docs

    
28.08.2018 / 15:51
0

Thanks for the clarifications. In my case, it was necessary to use an external script, since it was necessary to resize the parent div and the div's daughters and their respective contents. For this I used the script "javascript-detect-element-resize".

link: link

    
05.09.2018 / 11:24