automatically detect web browser window width change?

前端 未结 8 1521
清酒与你
清酒与你 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:15

    Here's a little piece of code I put together for the same thing.

    (function () {
        var width = window.innerWidth;
    
        window.addEventListener('resize', function () {
           if (window.innerWidth !== width) {
               window.location.reload(true);
           }
        });
    })();
    

提交回复
热议问题