Results 1 to 2 of 2

Thread: Resize iframe & textarea in reverse directions

  1. #1
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default Resize iframe & textarea in reverse directions

    Iframe isn't reziable in Firefox. Then I decided to put it in a div and resize that instead:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Resizable Iframe & Textarea</title>
    <style>
    #top, #bottom {
        width:300px;
        height:200px;
        border:1px solid #ccc;
        padding:10px;
    }
    #top {
        overflow:auto;
        resize:vertical;
    }
    iframe, textarea {
        display:block;
        width:100%;
        height:100%;
        margin:0;
        border:0;
        padding:0;
        resize:none;
        background:#ccc;
    }
    </style>
    </head>
    <body>
    <div id="parent">
        <div id="top">
            <iframe name="myFrame" src="about:blank"></iframe>
        </div>
        <div id="bottom">
            <textarea></textarea>
        </div>
    </div>
    <script>
        var parent = document.getElementById("parent").style.height;
        var top = document.getElementById("top").style.height;
        var bottom = document.getElementById("bottom").style.height;
        window.frames["myFrame"].onresize = function() {
            bottom = parent - top;
        }
    </script>
    </body>
    </html>
    Demo: http://jsfiddle.net/RainLover/EY4mR/

    Here's what I'd like to achieve: when I enlarge the top div, the bottom div should get smaller (and vice versa) so the parent div size remains fixed.

    Note: No frameset or jQuery plugin, please! All I need is a simple JavaScript approach to calculate and change the bottom div height as soon as I resize the top div.

    Thanks!

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Use inline style for parent, top and bottom, and use the script below:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Resizable Iframe & Textarea</title>
    <style>

    iframe, textarea {
    display:block;
    width:100%;
    height:100%;
    margin:0;
    border:0;
    padding:0;
    resize:none;
    background:#ccc;
    }
    </style>

    </head>

    <body>
    <div id="parent" style="position: relative; height: 400px; width: 300px; ">

    <div id="top" style="position: relative; height: 200px; width: 300px; border:1px solid #ccc; padding: 10px; overflow:auto; resize:vertical">
    <iframe src="about:blank" name="myFrame"></iframe>
    </div>

    <div id="bottom" style="position: relative; height: 200px; width: 300px; border:1px solid #ccc; padding: 10px">
    <textarea ></textarea>
    </div>

    </div>

    <script>
    window.frames["myFrame"].onresize=onload=function()
    {document.getElementById('bottom').style.height=parseInt(document.getElementById('parent').style.height)-parseInt(document.getElementById('top').style.height)+0+'px'}
    </script>

    </body>

    </html>
    Last edited by molendijk; 01-18-2014 at 10:53 PM.

  3. The Following User Says Thank You to molendijk For This Useful Post:

    Rain Lover (01-19-2014)

Similar Threads

  1. XML DISPLAY...(javascript) TEXTAREA TO IFRAME
    By ALICE1510 in forum JavaScript
    Replies: 0
    Last Post: 11-18-2011, 11:27 AM
  2. resize textarea in firefox
    By sublime99 in forum JavaScript
    Replies: 6
    Last Post: 01-04-2009, 04:31 PM
  3. IFRAME Scroller Moving in Two Directions ?
    By daddiekat in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 06-22-2007, 05:11 AM
  4. ssi script II, resizing content to fit iframe, instead of reverse
    By littlerobot in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 02-16-2007, 07:24 AM
  5. IFRAME scroller reverse direction
    By marcemig in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 10-20-2006, 01:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •