码迷,mamicode.com
首页 > Web开发 > 详细

js实现 iframe 宽高自适应

时间:2019-09-19 09:12:52      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:nbsp   eth   rip   tar   bsp   strong   ram   iframe   自适应   

css

<style type="text/css" media="screen">

.box{
  width: 80%;
  height: 500px;
  margin: 0 auto;
}
.left{
  width: 20%;
  height: 500px;
  float: left;
  border: 1px solid red;
}
#right{
  width: 79%;
  height: 500px;
  border: 1px solid red;
  float: left;
}
</style>

 

html

<div class="box">
  <div class="left">
    <a href="https://www.taobao.com/" title="" target="iframe_a">淘宝</a><br />
    <a href="https://www.jd.com/" title="" target="iframe_a">京东</a>
  </div>
  <div id="right">
    <iframe id="iframe" src="" name="iframe_a" frameborder="1" ></iframe>
  </div>
</div>

 

js

<script type="text/javascript">
  

<script type="text/javascript">
  var main = document.getElementById("right");
  var iframe = document.getElementById("iframe");
  var width = main.offsetWidth;
  var height = main.offsetHeight;
  iframe.style.width = width + "px";
  iframe.style.height = (height - 5) + "px";
</script>


</script>

js实现 iframe 宽高自适应

标签:nbsp   eth   rip   tar   bsp   strong   ram   iframe   自适应   

原文地址:https://www.cnblogs.com/quan846951943/p/11546520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!