automatically detect web browser window width change?

前端 未结 8 1419
清酒与你
清酒与你 2021-02-01 16:20

i know that you with $(window).width() can get the size of the web browser.

i want to detect when the user change the size of his web browser so i could readjust the col

相关标签:
8条回答
  • 2021-02-01 17:18

    Writing this down cause somehow none of these answers give the modern best-practices way of doing this:

    window.addEventListener("resize", function(event) {
        console.log(document.body.clientWidth + ' wide by ' + document.body.clientHeight+' high');
    })
    
    0 讨论(0)
  • 2021-02-01 17:21

    I use media="only screen and (min-width: 750px)" href="... css file for wide windows" media="only screen and (max-width: 751px)" href="...css file for mobiles"

    When I move the right windows border left and right to increase and decrease my window size, my web browser will automatically switch from the wide window to the mobile. I do not have to include any Javascript code to detect window width. This works for Chrome, Firefox and Internet Explorer on both Windows and Macintosh computers.

    0 讨论(0)
提交回复
热议问题