zoukankan      html  css  js  c++  java
  • 防止横竖屏时,iphone自动缩放的一段js代码

    function orientation_change() {
        var viewport = document.querySelector('meta[name="viewport"]');
        if (window.orientation == 0 || window.orientation == 180)
            viewport.setAttribute("content", "width=device-width, maximum-scale=1.0, initial-scale=1.0, user-scalable=no");
        else if (window.orientation == -90 || window.orientation == 90)
            viewport.setAttribute("content", "width=device-height, maximum-scale=1.0, initial-scale=1.0, user-scalable=no");     
    }
    
    window.onorientationchange = orientation_change;
    

      

    window.orientation
    :这个属性给出了当前设备的屏幕方向,0表示竖屏,正负90表示横屏(向左与向右)模式

    onorientationchange
    : 在每次屏幕方向在横竖屏间切换后,就会触发这个window事件,用法与传统的事件类似

     

     

    #b{300px;height:200px;background:blue;}
    @media screen and (orientation:portrait){
    #b{background:red;}
    }
    @media screen and (orientation:landscape){
    #b{background:green;}
    }
    

     

      

     

  • 相关阅读:
    r_action
    微内核 客户服务器模式 分布式
    机制与策略分离
    自顶向下设计
    swap
    专人写接口+模型,专人写业务逻辑---interface_model -- business logical
    14days laravel
    t
    不用print调试 xdebug ubuntu phpstorm 远程断点调试
    peewee sqlalchemy
  • 原文地址:https://www.cnblogs.com/xupeiyu/p/3957989.html
Copyright © 2011-2022 走看看