How can I detect window size with jQuery?

后端 未结 6 2027
谎友^
谎友^ 2020-12-08 04:17

How can I detect window/browser size with jQuery like Gmail? In Gmail, we don\'t need to refresh or reload current page as soon as we have changed window resolution in windo

6条回答
  •  情歌与酒
    2020-12-08 04:37

    You make one div somewhere on the page and put this code:

    Here is a snippet:

    var WindowsSize=function(){
        	var h=$(window).height(),
        		w=$(window).width();
        	$("#winSize").html("

    Width: "+w+"
    Height:"+h+"

    "); }; $(document).ready(WindowsSize); $(window).resize(WindowsSize);
    #winSize{
      position:fixed;
      bottom:1%;
      right:1%;
      border:rgba(0,0,0,0.8) 3px solid;
      background:rgba(0,0,0,0.6);
      padding:5px 10px;
      color:#fff;
      text-shadow:#000 1px 1px 1px,#000 -1px 1px 1px;
      z-index:9999
    }
    
    

    Of course, adapt it to fit your needs! ;)

提交回复
热议问题