DIV dynamically resizing using vertical slide

孤街醉人 提交于 2019-12-03 09:08:16

I created this functionality using 15 lines of JS/jQ: http://jsfiddle.net/xSJcz/

Hope it helps! You could easily modify it to respons to click, or similar.

EDIT: For future records, here is the answer's CSS:

#left,#right{
    border:1px solid #aaa;
    float:left;
    height:100px;
    width:48%;
}
#handle{
    background:#000;
    float:left;
    height:100px;
    margin:1px;
    width:1%;
}

HTML:

<div id="left">
    Left
</div>
<div id="handle"></div>
<div id="right">
    Right
</div>

JS:

var h = $('#handle'),
    l = $('#left'),
    r = $('#right'),
    w = $('body').width() - 18;

var isDragging = false;

h.mousedown(function(e){
    isDragging = true;
    e.preventDefault();
});
$(document).mouseup(function(){
    isDragging = false;
}).mousemove(function(e){
    if(isDragging){
        l.css('width', e.pageX);
        r.css('width', w - e.pageX);
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!