Hide div element when screen size is smaller than a specific size

前端 未结 9 2179
别跟我提以往
别跟我提以往 2020-12-04 17:41

I have a div element that I want to hide when the width of the browser is less than or equal to 1026px. Is this possible to do with the css: @media only scr

9条回答
  •  旧巷少年郎
    2020-12-04 18:29

    I don't know about CSS but this Javascript code should work:

        function getBrowserSize(){
           var w, h;
    
             if(typeof window.innerWidth != 'undefined')
             {
              w = window.innerWidth; //other browsers
              h = window.innerHeight;
             } 
             else if(typeof document.documentElement != 'undefined' && typeof      document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) 
             {
              w =  document.documentElement.clientWidth; //IE
              h = document.documentElement.clientHeight;
             }
             else{
              w = document.body.clientWidth; //IE
              h = document.body.clientHeight;
             }
           return {'width':w, 'height': h};
    }
    
    if(parseInt(getBrowserSize().width) < 1026){
     document.getElementById("fadeshow1").style.display = "none";
    }
    

提交回复
热议问题