美文网首页
标签内元素在屏幕内非裁切,居中

标签内元素在屏幕内非裁切,居中

作者: squidbrother | 来源:发表于2018-12-19 12:57 被阅读1次

    var isW = function(){ return document.documentElement.clientWidth; }

    var isH = function(){ return document.documentElement.clientHeight; }

    var oVp = document.getElementById('viewport');

    function css3(obj,attr,val){

    var str = attr.charAt(0).toUpperCase() + attr.substring(1);

    obj.style['Webkit'+str] = val;

    obj.style['Moz'+str] = val;

    obj.style['ms'+str] = val;

    obj.style['O'+str] = val;

    obj.style[attr] = val;

    }

    function setViewport(){

    var gameS = oVp.offsetWidth/oVp.offsetHeight;

    var screenS = isW()/isH();

    if(gameS>screenS){

    //高度拉伸

    var _tc = isW()/oVp.offsetWidth;

    css3(oVp,'transform','scale('+_tc+')');

    }else{

    //宽度拉伸

    var _tc = isH()/oVp.offsetHeight;

    css3(oVp,'transform','scale('+_tc+')');

    }

    }

    //resize

    function resizeSc(){

    if(window.orientation){

    window.addEventListener('orientationchange',function(){

    setViewport();

    },false);

    }else{

    window.addEventListener('resize',function(){

    setViewport();

    },false);

    }

    }

    resizeSc();

    相关文章

      网友评论

          本文标题:标签内元素在屏幕内非裁切,居中

          本文链接:https://www.haomeiwen.com/subject/wbxjkqtx.html