2009-08-05 25 views
15

私はこのコードを持っており、それが正常に動作します:サイズ変更のiFrame

ヘッド

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

ボディ

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

しかし、私は、私は "IFRAME" に私の "DIV" を変更したときこれ以上サイズを変更することはできません。一度に数ピクセル以上のマウスを移動するとき

ボディ

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

についてCheck out this linkとも答え:http://stackoverflow.com/a/13473569/676479のiframeで途切れサイズ変更を修正する方法を共有するための – Oleg

答えて

15

は少しグラグラ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イベントはインラインフレーム内からの気泡入りませんので、発生するようです。ブラウザがmousemoveイベントに追いつくことができる限り、サイズ変更ハンドラとハンドラCSSの大きな境界線を使用すると、iframeによって引き起こされる影響を最小限に抑えることができます。

+0

おかげで、それは狂気私を運転していました! :) – Rachel

+2

不安定なサイズ変更のもう一つの修正は、[here](http://bugs.jqueryui.com/attachment/ticket/4903/jquery.ui.resizable-iframeFix.patch)に掲載された 'iframeFix'パッチを追加することです。サイズ変更中にiframeがマウスをキャプチャするのを防ぎます。 – Rachel

1

私はこれがあなたが探しているものかもしれないと思う:あなたのiframeにあるものをdivに入れる。この例では、divに "container"というIDを与えます。

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

以下のコード私の仕事はスムーズです。

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

私はResize iframeをSearchさらにはこちらまで上陸した、しかし、それはiframeのサイズを変更するには、このページ検索に該当する未来の誰かのために役に立つかもしれませんので、この質問は、jQueryのUIのプラグインを使用してリサイズについては、私は答えを追加していています。 これはまた、すべての主要なブラウザには良いサポートを持っている唯一のCSS

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

を使用して行うことができます。ここでbrowser support

関連する問題