Detect browser window Maximized/Minimized with Javascript

后端 未结 1 1381
死守一世寂寞
死守一世寂寞 2020-12-19 04:01

When the user clicks the Maximized/Restore Down or Minimised buttons of the browser, is there a way to keep track of these events with javascript? Are there any appropriate

相关标签:
1条回答
  • 2020-12-19 04:46

    It sounds like what you want is a layout that resizes when the browser is resized but only up to a maximum width.

    If that's the case you can either do it in CSS or in JavaScript.

    Imagining that your content is in an element like:

    <div class="container"> -content here- </div>
    

    My preferred option would be to use CSS as follows:

    .container{
        max-width: 1200px;
        width: 100%;
    }
    

    If you need to support IE6 (which doesn't support max-width) you can try using an expression in the IE6 CSS:

    .container{
        width:expression(document.body.clientWidth > 1200 ? "1200px" : "100%" ); /*IE6*/
    }
    

    If you want to use JavaScript: you could just resize your elements in the window's resize event:

    $(window).bind('resize', function() {
        // resize $('.container').width() based on $(window).width()
    });
    

    You could initially trigger that logic using

    $(window).trigger('resize');
    
    0 讨论(0)
提交回复
热议问题