HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

Resize iframe & textarea in reverse directions

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
iframereverseresizetextareadirections

Problem

I have a textarea and iframe whose sizes should change dynamically and in reverse directions. I'd like to achive this effect without using a frameset or jQuery plugin. Here's the result of my attempt:


    
    Resize
    
        textarea,
        iframe {
            display: block;
            width: 300px;
            height: 200px;
            margin: 0;
            border: 0;
            padding: 0;
        }
        textarea {
            background: green;
            resize: none;
        }
        iframe {
            background: blue;
        }
    

    
    
    
    
        var slide = document.getElementById("slide");
        var textarea = document.getElementById("textarea");
        var iframe = document.getElementById("iframe");

        function resize() {
            var slideValue = slide.value;
            textarea.style.height = slideValue + "px";
            iframe.style.height = 400 - slideValue + "px";
        }
    


Demo

I wonder if you could review my code and let me know what you think.

Solution

Perhaps add overflow:hidden; to the CSS of the textarea and iframe, and add scrolling="no" as an attribute of the HTML iframe element: because otherwise, a scrollbar will appear when the slider is very big or very small.

Maybe a scrollbar is what you want (for usability); but a scrollbar makes a small visual artifact in an empty textbox or iframe, when the element is shorter than one line.

Context

StackExchange Code Review Q#39942, answer score: 3

Revisions (0)

No revisions yet.