【问题标题】:Resizing iFrame with jQuery UI使用 jQuery UI 调整 iFrame 的大小
【发布时间】:2010-11-17 01:49:02
【问题描述】:

我有这段代码,它工作正常:

头

    <script>
    $(document).ready(function()
    {
        $("#test").resizable({minHeight: 50, minWidth: 50});
    });
</script>

身体

<div id="test" style="border: .1em solid black;">
</div>

但是,当我将“div”更改为“iframe”时,我无法再调整它的大小了。

身体

<iframe id="test" style="border: .1em solid black;">
</iframe>

【问题讨论】:

标签: jquery iframe user-interface resize


【解决方案1】:

当一次移动鼠标超过几个像素时,发现 redsquare 的演示有点不稳定。我应用了一些修改,有助于更平滑地调整大小:

<html>
<head>
  <style type="text/css"> 
    #resizable { width: 150px; height: 150px; padding: 0.5em; }
    #resizable h3 { text-align: center; margin: 0; }
    .ui-resizable-helper { border: 75px solid #EFEFEF; margin: -75px; }
  </style> 
  <script type="text/javascript"> 
    $(function() {
      $("#resizable").resizable({
        helper: "ui-resizable-helper"
      });
    });
  </script> 
</head> 
<body> 
  <div class="demo"> 
    <div id="resizable" class="ui-widget-content"> 
      <iframe src="http://pastebin.me/f9ed9b9d36d17a7987e9cb670e01f0e2" class="ui-widget-content" frameborder="no" id="test" width="100%" height="100%" />
    </div> 
  <div>
</body>
</html>

似乎发生了调整大小的怪异事件,因为 mousemove 事件不会从 iframe 中冒出。只要浏览器能够跟上 mousemove 事件,在处理程序 CSS 中使用调整大小处理程序和大边框可以最大限度地减少 iframe 造成的影响。

【讨论】:

  • 感谢分享如何使用 iframe 修复不稳定的调整大小,这让我发疯了! :)
  • 调整大小不一的另一种解决方法是添加iframeFix 发布的here 补丁。它可以防止 iframe 在调整大小期间捕获鼠标。
【解决方案2】:

Below Code 顺利地为我工作。

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Resizable - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

  <style>

  #iframe {
  width: 100%;
  height: 100%;
  border: none;    

  background: #eee ;


  z-index: 1;
}

#resizable {
  width: 100px;
  height: 100px;
  background: #fff;
  border: 1px solid #ccc;


  z-index: 9;
}
  </style>
  <script>
  $(function() {
    $('#resizable').resizable({
      start: function(event, ui) {
        $('iframe').css('pointer-events','none');
         },
    stop: function(event, ui) {
        $('iframe').css('pointer-events','auto');
      }
  });
  });
  </script>
</head>
<body>

<div id="resizable">
  <iframe src="test.html" id="iframe">

</div>


</body>
</html>

【讨论】:

    【解决方案3】:

    我认为这可能是您正在寻找的:将 iframe 中任何内容的内容放在 div 中。对于这个例子,我会给 div 一个“容器”的 id。

    $('#ID_iframe').css("height", "" + $('#ID_iframe').contents().find("#container").height() + "px");
    

    【讨论】:

      【解决方案4】:

      我在这里搜索Resize iframe,但这个问题是关于使用 Jquery UI 插件调整大小的,我只是添加一个答案,因此它可能对将来进入此页面搜索调整 iframe 大小的人有所帮助。 这可以仅使用 CSS 来完成

      iframe {
        height: 300px;
        width: 300px;
        resize: both;
        overflow: auto;
      }
      

      所有主流浏览器也都有很好的支持。 Check out this link 以及关于browser support

      【讨论】:

        猜你喜欢
        • 2015-01-26
        • 2012-12-05
        • 1970-01-01
        • 1970-01-01
        • 2012-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-17
        相关资源
        最近更新 更多