Take a look at this:
http://jsfiddle.net/z0gqy9w2/3/
The edited code is as follows:
// Matrix regex to take the scale value property of $('#container') element var matrixRegex = /matrix\((-?\d*\.?\d+),\s*0,\s*0,\s*(-?\d*\.?\d+),\s*0,\s*0\)/, matches = $('#container').css('transform').match(matrixRegex); // Matches have this value : ["matrix(1.5, 0, 0, 1.5, 0, 0)", "1.5", "1.5"] , so we need matches[1] value : var scaleValue = matches[1]; $(".draggable").draggable({ cursor: "move", start: startFix, drag: dragFix, containment: [containmentArea.offset().left, containmentArea.offset().top, ( ( containmentArea.offset().left + ( containmentArea.width() * scaleValue ) ) - ( $(".draggable").width() * scaleValue ) ) , ( ( containmentArea.offset().top + ( containmentArea.height() * scaleValue ) ) - ( $(".draggable").height() * scaleValue ) ) ] });
As you can see, here is the trick:
( ( containmentArea.offset().left + ( containmentArea.width() * scaleValue ) ) - ( $(".draggable").width() * scaleValue ) )
Your right maximum position will be: The main offset of the left container + the true width of the container (with a scale) is the true width of the element (to insert it inside the container).
(Tip. Feel free to change the value of the "percent" var, since you also want to see the results)
regex ref
SerCrAsH Jul 12 '15 at 19:00 2015-07-12 19:00
source share