Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 隐藏iframe垂直滚动条并显示整个内容_Javascript_Html_Css_Iframe - Fatal编程技术网

Javascript 隐藏iframe垂直滚动条并显示整个内容

Javascript 隐藏iframe垂直滚动条并显示整个内容,javascript,html,css,iframe,Javascript,Html,Css,Iframe,我有一个iframe,它的内容超出了iframe的高度。我已经将iframe上的CSS设置为100vh的高度,但是它会裁剪掉内容。我想显示整个内容和不在该iframe中显示任何滚动条 实现这一目标的最佳方式是什么 HTML <iframe id="testIframe" width="100%" scrolling="no" style="display:block;"></iframe> 更新: 我不想调整滚动条,我想通过显示所有内容来删除它们。想象一下,我在一个页

我有一个iframe,它的内容超出了iframe的高度。我已经将iframe上的CSS设置为100vh的高度,但是它会裁剪掉内容。我想显示整个内容在该iframe中显示任何滚动条

实现这一目标的最佳方式是什么

HTML

 <iframe id="testIframe" width="100%" scrolling="no" style="display:block;"></iframe>
更新:
我不想调整滚动条,我想通过显示所有内容来删除它们。想象一下,我在一个页面(可滚动)上有一个iframe窗口(不可滚动)。

您可以使用以下css代码调整iframe或任何元素的滚动条:


iframe{width:500px;height:500px;overflow-x:hidden;overflow-y:scroll}

您可以使用以下css代码调整iframe或任何元素的滚动条:


iframe{width:500px;height:500px;overflow-x:hidden;overflow-y:scroll}

您必须知道iframe中内容的纵横比。 例如,在youtube视频中,它是16:9

iframe {
    // Aspect ratio 16:9 
    // width:height
    width: 177.77vH;// (100vH / 9) * 16
    height: 100vH;

}

您必须知道iframe中内容的纵横比。 例如,在youtube视频中,它是16:9

iframe {
    // Aspect ratio 16:9 
    // width:height
    width: 177.77vH;// (100vH / 9) * 16
    height: 100vH;

}

实际上,我自己使用jQuery的这种方法解决了这个问题

$('testIframe').on('load', function(){
      resizeIframe(this);
    });
...
function resizeIframe(obj) {    
  // Initially just set the height to 100% till the inner page loads and once the page inside the iframe is loaded
  // then set the iframe height to match that page height so that it looks seamless to the user
  obj.style.height = "100vH";

  setTimeout(function(){
    obj.style.display = "block";
    obj.style.height = $(obj.contentWindow.document.body).height() + "px";
  }, 1500);
}

实际上,我自己使用jQuery的这种方法解决了这个问题

$('testIframe').on('load', function(){
      resizeIframe(this);
    });
...
function resizeIframe(obj) {    
  // Initially just set the height to 100% till the inner page loads and once the page inside the iframe is loaded
  // then set the iframe height to match that page height so that it looks seamless to the user
  obj.style.height = "100vH";

  setTimeout(function(){
    obj.style.display = "block";
    obj.style.height = $(obj.contentWindow.document.body).height() + "px";
  }, 1500);
}

但这不会添加一个垂直滚动条吗?在fiddle中添加您的代码,这样我们就可以查看您的css和iframe代码。但这不会添加一个垂直滚动条吗?在fiddle中添加您的代码,这样我们就可以查看您的css和iframe代码。是的,这很好,但是我仍然无法摆脱滚动条并显示所有内容,无论如何内容很长。如果纵横比正确,可以看到整个内容<代码>溢出:隐藏的应该会删除滚动条。您可以共享一个JSFIDLE,以便我们更好地了解问题所在。是的,这很好,但是无论内容有多长,我仍然无法摆脱滚动条并显示所有内容。如果纵横比正确,可以看到整个内容<代码>溢出:隐藏的应该删除滚动条。您可以共享一个JSFIDLE,以便我们更好地了解问题所在。我不想调整滚动条,我想通过显示所有内容来删除它们。想象一下,我在一个页面(可滚动)上有一个iframe窗口(不可滚动)。我不想调整滚动条,我想通过显示所有内容来删除它们。想象一下,我在一个页面(可滚动)上有一个iframe窗口(不可滚动)。