JavaScript window resize event

前端 未结 13 786
余生分开走
余生分开走 2020-11-22 00:58

How can I hook into a browser window resize event?

There\'s a jQuery way of listening for resize events but I would prefer not to bring it into my project for just t

13条回答
  •  执念已碎
    2020-11-22 01:18

    First off, I know the addEventListener method has been mentioned in the comments above, but I didn't see any code. Since it's the preferred approach, here it is:

    window.addEventListener('resize', function(event){
      // do stuff here
    });
    

    Here's a working sample.

提交回复
热议问题