css布局-div中實現resize的拉動分欄


resize的鼠標拉動分欄效果:主要通過resize設置橫向自由拉伸來調整目標元素的寬度

resize 屬性規定是否可由用戶調整元素的尺寸。如果希望此屬性生效,需要設置元素的 overflow 屬性,值可以是 auto、hidden 或 scroll。

resize: none|both|horizontal|vertical;

結合多行文本輸入框實現效果:

下面是代碼:

  //css:
 .stretching-column {
            overflow: hidden;
            border: 1px solid gray;
            width: 600px;
            height: 300px;
            line-height: 20px;
            font-size: 16px;
            color: orange;

        }

        .left {
            overflow: hidden;
            float: left;
            position: relative;
            height: 100%;
        }

        .right {
            overflow: hidden;
            padding: 10px;
            height: 100%;
            background-color: #f0f0f0;
            word-break: break-all;
        }

        .resize-bar {
            overflow: scroll;
            width: 250px;
            height: 100%;
            opacity: 0;
            resize: horizontal;
        }

        .resize-bar::-webkit-scrollbar {
            width: 250px;
            height: 100%;
        }

        .resize-bar:hover,
        :active .resize-line {
            border-left: 1px dashed gray;
        }

        .resize-line {
            position: absolute;
            right: 0;
            top: 0;
            bottom: 0;
            border-left: 1px solid #ccc;
            border-right: 2px solid #f0f0f0;
            pointer-events: none;
        }

        .resize-text {
            overflow-x: hidden;
            position: absolute;
            left: 0;
            right: 5px;
            top: 0;
            bottom: 0;
            padding: 10px;
            word-break: break-all;
        }
        .my-textarea {
            width: 100%;
            height: 100%;
            padding: 10px;
            outline: none;
        }

//html:
<div class="stretching-column">
            <div class="left">
                <div class="resize-bar"></div>
                <div class="resize-line"></div>
                <div class="resize-text">
                    在遠方的時候 又想你到淚流 這矯情的措辭結構 經歷過的人會懂 那些不堪言的疼痛 也就是我自作自受 你沒有裝聾 你真沒感動 一個人的時候 偷偷看你的微博 你轉播的歌好耳熟
                    我們坐一起聽過 當日嫌它的唱法做作 現在聽起來竟然很生動 可能是時光讓耳朵變得寬容 如今一個人聽歌總是會覺得失落 幻聽你在我的耳邊輕輕訴說 夜色多溫柔 你有多愛我
                    如今一個人聽歌總是會覺得難過 愛已不在這里我卻還沒走脫 列表里的歌 隨過往流動
                </div>
            </div>
            <div class="right">
                <textarea class="my-textarea" autofocus="autofocus" placeholder="說說心里話...">
                    
                </textarea>
            </div>
        </div>


//js:
        let leftEle = document.querySelector(".resize-text");
        let rightEle = document.querySelector(".my-textarea");
        rightEle.oninput = function (){
            leftEle.innerHTML = rightEle.value;
        }    

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM