I am trying to create a sliding, resizable bar inside a container. For some reason, the resizing method converts the div from position: Regarding position: Absolute. This visually moves the box and destroys the scroll action of the container container.
JSFiddle example
I tried connecting to the Stop and Resize event and moving back to Position: Relative, but this is pretty hacked and the results are not perfect. Seems this should work?
JQuery
$(document).ready(function () { $(".Timeline").draggable({ axis: "x", containment: "parent" }) .resizable({ containment: "parent", handles: 'e, w' }); });
HTML:
<div style="width: 800px; overflow: auto;"> <div id="TimelineCanvas"> <div class="TimelineContainer"> <div class="Timeline"> </div> </div> </div> </div>
Style:
#TimelineCanvas { width: 2000px; height: 150px; } .TimelineContainer { height: 75px; width: 100%; border: 1px solid black; } .Timeline { position: relative; height: 75px; width: 75px; background-color: Gray; cursor: move; }
My best attempt to fix:
$(document).ready(function () { $(".Timeline").draggable({ axis: "x", containment: "parent" }) .resizable({ containment: "parent", handles: 'e, w', resize: function (event, ui) { $(this).css("height", ''); }, stop: function (event, ui) { $(this).css("position", ''); $(this).css("top", ''); $(this).css("height", ''); } }); });
Any help would be greatly appreciated; thanks!
source share