How to use javascript conditionally like CSS3 media queries, orientation?

前端 未结 6 1415
猫巷女王i
猫巷女王i 2020-11-29 19:37

How to use javascript conditionally like CSS3 media queries, orientation?

For Example I can write css for specific

@media only screen and (width : 10         


        
6条回答
  •  一向
    一向 (楼主)
    2020-11-29 20:26

    The simplest way I found is to get the width of our page; then to conditionally use it.

    var x = document.documentElement.clientWidth;
    if (x < 992)            
            document.body.style.backgroundColor = "yellow";

提交回复
热议问题