HTML+JS将div的高和宽按比例复制给另一个DIV

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
#dom2{
    width:450px;
    height: 450px;
    background-color: black;
}
#as{
    background-color: red;
}
    </style>
</head>
<body>
    <div id="dom2"></div>
    <div id="as"></div>

    <script>
    var width=document.getElementById('dom2').offsetWidth;
    var height=document.getElementById('dom2').offsetHeight;
    var nh=height*16/9;
    document.getElementById('as').style.width=width+"px";
    document.getElementById('as').style.height=nh+"px";
    </script>
</body>
</html>

 

posted @ 2017-03-17 18:16  ZM姐姐  阅读(992)  评论(0编辑  收藏  举报