I have a problem and I want to do that can move 3 div (more later) to move in the X axis min and max have a position relative to the container. Initially works well but when you start moving the separators several times begins the problem, does not respect the minimum or the maximum, I wonder if someone can help me to know what could be the problem (They can check in the browser console where the values are updated according to move the separators are.) https://jsfiddle.net/66un403y/
$( document ).ready(function() {
$(function(){
var A = parseInt($('#A').width()),
B = parseInt($('#B').width()),
C = parseInt($('#C').width()),
minw = parseInt((A + B + C) * 10 / 100), // min 10 percentage
offset = $('#container').offset(),
containw = $('#container').outerWidth(),
splitter_1 = $('#container').outerWidth() / 3;
splitter_2 = (($('#container').outerWidth() / 3) * 2);
$("#min_width").text(minw + "px");
splitter = function(event, ui){
$( '#DragContent' ).unbind( 'draggable' );
A = parseInt(ui.position.left);
B = Math.abs(containw - A - C);
C = containw - A - B;
splitter_1 = ui.position.left;
splitter_2 = splitter_2;
console.log("A:" + A);
console.log("B:" + B);
console.log("C:" + C);
console.log("splitter_1:" + splitter_1);
console.log("splitter_2:" + splitter_2);
console.log("offset.left:"+offset.left);
console.log("ui.position.left:"+ ui.position.left);
console.log("max:"+ (A + B - minw));
console.log("min:"+ ( minw ));
// update the new limits
//$( '#X' ).unbind( 'draggable' );
$( '#X' ).draggable({
containment : [
offset.left + minw,
offset.top,
offset.left + C + B - minw,
offset.top + $('#container').height()
]});
//set widths and information...
$('#A').css({width : A}).children().text("current px: " + A);
$('#B').css({width : B}).children().text("current px: " + B);
$('#C').css({width : C}).children().text("current px: " + C);;
};
splitter2 = function(event, ui){
C = containw - (ui.position.left);
B = Math.abs( ui.position.left - A );//parseInt(ui.position.left) - A - C;
A = containw - (B + C);
splitter_1 = splitter_1;
splitter_2 = ui.position.left;
console.log("A:" + A);
console.log("B:" + B);
console.log("C:" + C);
console.log("splitter_1:" + splitter_1);
console.log("splitter_2:" + splitter_2);
console.log("offset.left:"+offset.left);
console.log("ui.position.left:"+ ui.position.left);
console.log("limite:"+ (containw - minw));
console.log("minimo:"+ ( A + minw ));
// update the new limits
//$( '#X' ).unbind( 'draggable' );
$('#Z').draggable({
containment : [
offset.left + A + minw,
offset.top,
offset.left + containw - minw,
offset.top + $('#container').height()
]});
$('#A').css({width : A}).children().text("current px: " + A);
$('#B').css({width : B}).children().text("current px: " + B );
$('#C').css({width : C}).children().text("current px: " + C );
};
$('#X').draggable({
axis : 'x',
drag : splitter,
containment : [
offset.left + minw,
offset.top,
offset.left + C + B - minw,
offset.top + $('#container').height()
]
});
$('#Z').draggable({
axis : 'x',
drag : splitter2,
containment : [
offset.left + A + minw,
offset.top,
offset.left + containw - minw,
offset.top + $('#container').height()
]
});
//information...
$('#width').text(A + B + C);
$('#A div').text("current px: " + A );
$('#B div').text("current px: " + B );
$('#C div').text("current px: " + C );
console.log();
});
});