Javascript jQuery 调整 iframe 高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11873312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 07:28:46  来源:igfitidea点击:

jQuery adjusting iframe height

javascriptjqueryiframeheight

提问by Henrik Petterson

This code was passed to me. It makes my iframe set to 100% height of the screen:

这段代码传给了我。它使我的 iframe 设置为屏幕的 100% 高度:

jQuery(document).ready(function(){var height = $(window).height();
             $('iframe').css('height', height)
         });

I am new to javascript. How can I edit this code to make it set to 90% height rather than 100%? Also, this code targets all iframes, is there any way to make it target a specific iframe (by its ID or NAME value)? You can fiddle with this code here if you wish: http://jsfiddle.net/VurLy/

我是 javascript 新手。如何编辑此代码以将其设置为 90% 的高度而不是 100%?此外,此代码针对所有 iframe,有没有办法使其针对特定 iframe(通过其 ID 或 NAME 值)?如果你愿意,你可以在这里摆弄这段代码:http: //jsfiddle.net/VurLy/

回答by Ry-

Multiply it by 90%?

乘以 90%?

jQuery(document).ready(function() {
    var height = $(window).height();
    $('iframe').css('height', height * 0.9 | 0);
});

As for targeting by ID or name, just pass the appropriate selector to $instead of 'iframe'.

至于按 ID 或名称定位,只需将适当的选择器传递给$而不是'iframe'

回答by mittmemo

jQuery(document).ready(function(){
    $('#YOUR_FRAME_ID_HERE').css('height', '90%')
});?

回答by Scott Selby

in jquery you can identify which elemtents you want many different way , most popular is by the id like this $('#scoop') or by class , like this $('.scoop') - if the class was scoop

在 jquery 中,您可以通过多种不同的方式识别您想要的元素,最流行的是通过 id 像这样 $('#scoop') 或通过类,像这样 $('.scoop') - 如果类是 scoop

so that is how you identify the specific iFrame you want , then change the height like this

所以这就是你识别你想要的特定 iFrame 的方式,然后像这样改变高度

 jQuery(document).ready(function() {
   var height = $(window).height();
   $('#scoop').css('height', '90%'); 
});