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;

  • 相关阅读:
    Java学习十一天
    Java学习第十天
    Java学习第九天
    Java学习第八天
    Java学习第七天
    Java学习第六天
    Java学习第五天
    Java学习第四天
    Java第三天
    京峰教育-笔记
  • 原文地址:https://www.cnblogs.com/luckyXcc/p/5946492.html
Copyright © 2011-2022 走看看