So I've got a container with three columns in it that need to be resizable. The container itself will eventually need to be resizable too, but for now it can be static, as long as the columns inside can be flexible on drag.
I thought I had the right idea but it isn't quite there. When resizing, some parts move correctly, but others jump around either behind or resize part way correctly then start moving backwards. You can see it here in what I have so far, grabbing the middle handles and trying to resize:
http://jsbin.com/arulel/1/edit
Any help would be appreciated, and it only needs to work in Firefox. Preferably without extra plugins, if possible.
Here is the code as well:
<div id="container">
<div id="col1" class="col">
<p>"Lorem ipsum.."</p>
</div>
<div class="resizer first"></div>
<div id="col2" class="col">
<p>"Lorem ipsum.."</p>
</div>
<div class="resizer second"></div>
<div id="col3" class="col">
<p>"Lorem ipsum..."</p>
</div>
</div>
CSS:
#container {
background: none no-repeat 0 0 scroll #aaa;
height: 600px;
border-radius: 0 0 6px 6px;
width: 700px;
position: relative;
}
.col {
height: 100%;
position: absolute;
z-index: 8000;
padding: 0 10px;
}
.first {
width: 4px;
height: 100%;
position: absolute;
left: 33.33%;
background-color: white;
z-index: 9000;
}
.second {
width: 4px;
height: 100%;
position: absolute;
right: 33.33%;
background-color: white;
z-index: 9000;
}
.resizer:hover {
cursor: col-resize;
}
#col1 {
background: none no-repeat 0 0 scroll #444;
border-radius: 0 0 0 6px;
left: 0;
right: calc(66.66% - 4px);
}
#col2 {
background: none no-repeat 0 0 scroll #111;
left: calc(33.33% + 4px);
right: calc(33.33% - 4px);
color: white;
}
#col3 {
background: none no-repeat 0 0 scroll #777;
border-radius: 0 0 6px 0;
left: calc(66.66% - 4px);
right: 0;
}
Javascript/jQuery:
$(document).ready(function(){
$(".first").on("mousedown", function(e){
mousedownFirst = true;
});
$(".second").on("mousedown", function(e){
mousedownSecond = true;
});
$("#container").on("mouseup", function(e){
mousedownFirst = false;
mousedownSecond = false;
});
$("#container").on("mousemove", function(e){
parentOffset = $(this).offset();
if(mousedownFirst){
$(".first").css("left", e.pageX - parentOffset.left);
$("#col1").css("right", e.pageX - parentOffset.left);
$("#col2").css("left", e.pageX - parentOffset.left);
}
if(mousedownSecond){
$(".second").css("left", e.pageX - parentOffset.left);
$("#col2").css("right", e.pageX - parentOffset.left);
$("#col3").css("left", e.pageX - parentOffset.left);
}
});
});