使用jQuery UI调整iFrame大小 [英] Resizing iFrame with jQuery UI

查看:386
本文介绍了使用jQuery UI调整iFrame大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have this code and it works fine:

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

正文

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

然而,当我将div更改为iframe时,我无法再调整它。

However when I change my "div" into "iframe" I can't resize it anymore.

正文

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


推荐答案

发现redsquare的演示在移动鼠标时有点不稳定一次只有几个像素。我已经应用了一些修改,有助于使调整大小更顺畅:

Found redsquare's demo a bit wonky when moving the mouse more than a few pixels at a time. I've applied a couple modifications that help make resizing a lot smoother:

<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中使用resize处理程序和大边框可以最大限度地减少iframe造成的影响。

The weirdness of resizing seems to happen because mousemove events don't bubble up from within the iframe. Using a resize handler and a large border in the handler CSS minimizes the effect caused by the iframe as long as the browser can keep up with the mousemove events.

这篇关于使用jQuery UI调整iFrame大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆