zoukankan      html  css  js  c++  java
  • 自适应背景图,不变形,不留空白

    var backgroundImgDiv = document.getElementById("backgroundImgDiv");
    var img = backgroundImgDiv.getElementsByTagName("img")[0];

    (setImgSize=function(){
    var windowWidth = document.documentElement.clientWidth || document.body.clientWidth;
    var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
    document.body.style.height = windowHeight + "px";
    var cale = windowWidth/windowHeight;
    if (cale >= 1920/1080) {
    backgroundImgDiv.style.width = windowWidth+'px';
    img.style.width = windowWidth+'px';

    backgroundImgDiv.style.height = "auto";
    img.style.height= "auto";
    } else{
    backgroundImgDiv.style.width = "auto";
    img.style.width = "auto";

    backgroundImgDiv.style.height = windowHeight+'px';
    img.style.height= windowHeight+'px';
    }
    })();
    window.onresize=setImgSize;

  • 相关阅读:
    cocos2d 多点触摸
    mac 下安装node.js
    黑鹰破解笔记(2)
    OD使用心得笔记二
    淘宝店开始进行审核
    黑鹰破解笔记(1)
    Lisp笔记1
    OD使用心得笔记一
    怒马
    近段时间的web开发
  • 原文地址:https://www.cnblogs.com/luckyXcc/p/5946492.html
Copyright © 2011-2022 走看看