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;}
    }
    

     

      

     

  • 相关阅读:
    模板
    CF1271E Common Number
    模板——长链剖分
    XJOI NOIP501/511训练22 ttt学字符串
    POJ 1151 Atlantis
    BZOJ 1014 [JSOI2008]火星人prefix
    Luogu P1856 [USACO5.5]矩形周长Picture
    CF716D Complete The Graph
    Luogu P2596 [ZJOI2006]书架
    HTML 学习之JavaScript作用域
  • 原文地址:https://www.cnblogs.com/xupeiyu/p/3957989.html
Copyright © 2011-2022 走看看