使用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.