Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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
使用jQuery UI调整iFrame的大小_Jquery_Iframe_User Interface_Resize - Fatal编程技术网

使用jQuery UI调整iFrame的大小

使用jQuery UI调整iFrame的大小,jquery,iframe,user-interface,resize,Jquery,Iframe,User Interface,Resize,我有这个代码,它工作得很好: 头 $(文档).ready(函数() { $(“#测试”)。可调整大小({minHeight:50,minWidth:50}); }); 身体 但是,当我将“div”更改为“iframe”时,我无法再调整它的大小 身体 一次移动鼠标超过几个像素时,发现redsquare的演示有点不稳定。我已经应用了一些修改,有助于使调整大小更加平滑: <html> <head> <style type="text/css">

我有这个代码,它工作得很好:


$(文档).ready(函数()
{
$(“#测试”)。可调整大小({minHeight:50,minWidth:50});
});
身体


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

身体


一次移动鼠标超过几个像素时,发现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>

#可调整大小{宽度:150px;高度:150px;填充:0.5em;}
#可调整大小的h3{文本对齐:居中;边距:0;}
.ui可调整大小的辅助对象{边框:75px实心#EFEFEF;边距:-75px;}
$(函数(){
$(“#可调整大小”)。可调整大小({
帮助程序:“ui可调整大小的帮助程序”
});
});

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

我认为这可能就是您想要的:将iframe中任何内容的内容放在一个div中。在本例中,我将为该div指定一个id“container”


下面的代码为我工作顺利的方式

<!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>

jQuery UI可调整大小-默认功能
#iframe{
宽度:100%;
身高:100%;
边界:无;
背景:#eee;
z指数:1;
}
#可调整大小{
宽度:100px;
高度:100px;
背景:#fff;
边框:1px实心#ccc;
z指数:9;
}
$(函数(){
$(“#可调整大小”)。可调整大小({
开始:功能(事件、用户界面){
$('iframe').css('pointer-events','none');
},
停止:功能(事件、用户界面){
$('iframe').css('pointer-events','auto');
}
});
});

我在这里登陆是为了搜索
调整iframe的大小
,但这个问题是关于使用Jquery UI插件调整大小的,我只是添加了一个答案,以便将来可能会有人在这个页面搜索时调整iframe的大小。 这只能使用CSS来完成

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

而且所有主要的浏览器都有很好的支持。还有关于

感谢分享如何用iframes修复起伏的调整大小,这让我发疯了!:)另一种解决方法是添加
iframeFix
补丁。它防止iframes在调整大小时捕获鼠标。以下是答案:
<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>
$('#ID_iframe').css("height", "" + $('#ID_iframe').contents().find("#container").height() + "px");
<!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>
iframe {
  height: 300px;
  width: 300px;
  resize: both;
  overflow: auto;
}