简体   繁体   English

JS-Iframe高度调整

[英]JS - Iframe Height Resize

I have this 我有这个

 <script>
     var calcHeight = function() {
       $('#iframe').height($(window).height());
     };
     $(document).ready(function() {
       calcHeight();
     });

     $(window).resize(function() {
       calcHeight();
     }).load(function() {
       calcHeight() ;
     }); </script>

The above JS just resizes the height. 上面的JS只是调整了高度。 How to I edit the above JS and add to the calculated height 10px? 如何编辑上面的JS并添加到计算的高度10px?

For example if the JS calculates 700px, I need to have the height as 710px. 例如,如果JS计算700px,则需要将高度设置为710px。

You can use css calc() along with vh unit to do the calculations for you 您可以将css calc()与vh单位一起使用来进行计算

iframe {
    height:calc(100vh + 10px);    
}

JSFiddle demo JSFiddle演示

calc() compatibility calc()兼容性

Viewport units compatibility 视口单位兼容性

If you wish to continue using JS just add 10 to the returned height 如果您想继续使用JS,只需在返回的高度上加10

$('#iframe').height($(window).height() + 10);

Maybe something like this 也许像这样

<script>
 var calcHeight = function() {
   $('#iframe').height(10 + +$(window).height());
 };
 $(document).ready(function() {
   calcHeight();
 });

 $(window).resize(function() {
   calcHeight();
 }).load(function() {
   calcHeight() ;
 }); </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM