简体   繁体   中英

DOMWindow popup auto resize to contents?

I'm using JQuery and learning as I go, I was just curious is there a way to have a DOMwindow auto resize to its content?

I managed to figure out how to change the parameters to take % width and height instead of px but I'm finding that a dynamic resizing view would utilize my site's purpose better.

Should I be looking into a different type of code to accomplish this?

If you had a containing wrap element, which holds all of the content, and is not set to 100%:

<div id="main_container">
    // page contents
</div>

You could now get the dimensions of the containing element and then resize your window to suit.

In jQuery:

$(document).ready(function() {
    var myElement = $('#main_container');
    var sWidth = myElement.width();
    var sHeight = myElement.height();

    window.resizeTo(sWidth, sHeight);
})

There are other ways of doing this, if you search thoroughly on this website, you will find your answer. You can use (document).width() and (window).width() , as this answer describes: jQuery(document).width() doesn't include width outside of viewable area

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM