DIV dynamically resizing using vertical slide

删除回忆录丶 提交于 2019-12-09 07:14:19

问题


This is a little hard to explain, but I'm going to do my best:

My webpage is divided using two divs: one floating at left, and other floating at right (50% each one more or less).

I want to add a new feature: dynamically resize. That is: when I click on right border of DIV#1 or click on left border of DIV#2, each one should resize from left to right or right to left.

Maybe you don't understand me, but this effect is what I need (from this plugin):

This plugin only works for images, not divs. I need the same effect on my divs. Actually, I'm trying to use JQueryUI Resizable class but I don't know how to synchronize both resizes.

Can you help me? Any suggestion or track about this would be really appreciated. Thanks!


回答1:


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);
    }
});


来源:https://stackoverflow.com/questions/5180806/div-dynamically-resizing-using-vertical-slide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!