四宮格拖動改變寬高

四宮格拖動改變寬高.gif

javascript

var areaBox = choose("tableArea"), //獲取最外圍窗口
                leftArea = choose("boxArea");//獲取四宮格中的第一個容器
                areBoxW = areaBox.clientWidth;//獲取最外圍窗口的寬
                areBoxH = areaBox.clientHeight;//獲取最外圍窗口的高
                lineH = choose("lineHeight"),//獲取橫的虛線
                lineW = choose("lineWidth");//獲取豎的虛線
            lineW.onmousedown = function(e) {
                // 移動容器的寬
                 var disX = (e || event).clientX;//獲取鼠標(即橫線)當前X軸坐標
                 lineW.left = lineW.offsetLeft;//獲取鼠標(即橫線)當前左邊距
                 document.onmousemove = function(e) { 
                        var iT = lineW.left + ((e || event).clientX - disX);//iT = 橫線的左邊距 - (鼠標移動后的當前X坐標 - 初始時鼠標(即橫線)的X軸坐標
                        var e=e||window.event,tarnameb=e.target||e.srcElement;
                        if(iT <= "100" || areBoxW - iT <= "100"){
                            // 當鼠標移動至最左或最右時釋放鼠標
                            document.onmousemove = null;
                            document.onmouseup = null; 
                            lineW.releaseCapture && lineW.releaseCapture();//從當前線程中的窗口釋放鼠標捕獲涛贯,并恢復通常的鼠標輸入處理
                            return false
                        }else{
                            lineW.style.left = leftArea.style.width = iT + "px";//設(shè)計橫線的左邊距和第一個容器的寬
                        }
                 }; 
                 document.onmouseup = function() {
                      document.onmousemove = null;
                      document.onmouseup = null; 
                      // lineW.releaseCapture && lineW.releaseCapture()
                 };
                 lineW.setCapture && lineW.setCapture();
                 return false
             };
             lineH.onmousedown = function(e) {
                // 移動容器的高
                 var disY = (e || event).clientY;
                 lineH.top = lineH.offsetTop;
                 document.onmousemove = function(e) { 
                      var iT = lineH.top + ((e || event).clientY - disY);
                      var e=e||window.event,tarnameb=e.target||e.srcElement;
                      console.log(areBoxH);
                      console.log(iT);
                        if(iT <= "70" || areBoxH - iT <= "70"){
                            document.onmousemove = null;
                            document.onmouseup = null; 
                            lineH.releaseCapture && lineH.releaseCapture()
                            return false
                        }else{
                            lineH.style.top = leftArea.style.height =  iT + "px";
                        }
                 }; 
                 document.onmouseup = function() {
                      document.onmousemove = null;
                      document.onmouseup = null; 
                      lineH.releaseCapture && lineH.releaseCapture()
                 };
                 lineW.setCapture && lineW.setCapture();
                 return false
             };
function choose(id){
    return document.getElementById(id);
};

html

    <div class="wrapper">
        <table id="tableArea" class="table-area" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td id="boxArea">
                    <div class="area"><div class="area-title">公告</div></div>
                </td>
                <td>
                    <div class="area"><div class="area-title">公告</div></div>
                </td>
            </tr>
            <tr>
                <td>


                    <div class="area"><div class="area-title">公告</div></div>
                </td>
                <td>
                    <div class="area"><div class="area-title">公告</div></div>
                </td>
            </tr>
        </table>
        <div id="lineHeight" class="drag-line-h"></div>
        <div id="lineWidth" class="drag-line-w"></div>
    </div>

css

body{background:#F2F3F4;}
body,html,.wrapper,#tableArea,#tableArea td .area{margin:0;padding:0;height:100%;width:100%;}
.wrapper{position:relative;}
#tableArea td{padding:10px;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;}
.area{background:#fff;border-radius:5px;-webkit-border-radius:5px;-moz-border-radius:5px;position:relative;}
.area-title{font-size:14px;border-bottom:1px solid #d9d9d9;width:97%;margin:0 auto;height:45px;line-height:45px;position:relative;}
.area-title:after{content:"";position:absolute;width:3px;height:40%;top:30%;background:#54ACF1;left:-1.5%;}
.drag-line-h,.drag-line-w{position:absolute;z-index:1;cursor:move;}
.drag-line-h{width:100%;border-bottom:2px dashed #83dee4;left:0;top:50%;}
.drag-line-w{height:100%;border-left:2px dashed #83dee4;top:0;left:50%;}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末坝辫,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子汹粤,更是在濱河造成了極大的恐慌命斧,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,858評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件嘱兼,死亡現(xiàn)場離奇詭異国葬,居然都是意外死亡,警方通過查閱死者的電腦和手機芹壕,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評論 3 395
  • 文/潘曉璐 我一進店門汇四,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人踢涌,你說我怎么就攤上這事通孽。” “怎么了斯嚎?”我有些...
    開封第一講書人閱讀 165,282評論 0 356
  • 文/不壞的土叔 我叫張陵利虫,是天一觀的道長挨厚。 經(jīng)常有香客問我堡僻,道長糠惫,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,842評論 1 295
  • 正文 為了忘掉前任钉疫,我火速辦了婚禮硼讽,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘牲阁。我一直安慰自己固阁,他們只是感情好,可當我...
    茶點故事閱讀 67,857評論 6 392
  • 文/花漫 我一把揭開白布城菊。 她就那樣靜靜地躺著备燃,像睡著了一般。 火紅的嫁衣襯著肌膚如雪凌唬。 梳的紋絲不亂的頭發(fā)上并齐,一...
    開封第一講書人閱讀 51,679評論 1 305
  • 那天,我揣著相機與錄音客税,去河邊找鬼况褪。 笑死,一個胖子當著我的面吹牛更耻,可吹牛的內(nèi)容都是我干的测垛。 我是一名探鬼主播,決...
    沈念sama閱讀 40,406評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼秧均,長吁一口氣:“原來是場噩夢啊……” “哼食侮!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起目胡,我...
    開封第一講書人閱讀 39,311評論 0 276
  • 序言:老撾萬榮一對情侶失蹤疙描,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后讶隐,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體起胰,經(jīng)...
    沈念sama閱讀 45,767評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年巫延,在試婚紗的時候發(fā)現(xiàn)自己被綠了效五。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,090評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡炉峰,死狀恐怖畏妖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情疼阔,我是刑警寧澤戒劫,帶...
    沈念sama閱讀 35,785評論 5 346
  • 正文 年R本政府宣布半夷,位于F島的核電站,受9級特大地震影響迅细,放射性物質(zhì)發(fā)生泄漏巫橄。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,420評論 3 331
  • 文/蒙蒙 一茵典、第九天 我趴在偏房一處隱蔽的房頂上張望湘换。 院中可真熱鬧,春花似錦统阿、人聲如沸彩倚。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽帆离。三九已至,卻和暖如春结澄,著一層夾襖步出監(jiān)牢的瞬間哥谷,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評論 1 271
  • 我被黑心中介騙來泰國打工概而, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留呼巷,地道東北人。 一個月前我還...
    沈念sama閱讀 48,298評論 3 372
  • 正文 我出身青樓赎瑰,卻偏偏與公主長得像王悍,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子餐曼,可洞房花燭夜當晚...
    茶點故事閱讀 45,033評論 2 355

推薦閱讀更多精彩內(nèi)容