I created a “2d slider” in jQuery in which two parameters are processed simultaneously by dragging the “handle” into the bounding box.
I implemented this by nesting the div handle in the parent div and using the jQuery UI plugin to facilitate drag and drop behavior. The html looks like this:
<div class="Slider2d" id="grid_spacing_both"> <div class="Slider2dHandle" id="grid_spacing_both_handle"></div> </div>
jQuery looks like this:
$(".Slider2dHandle").draggable({ containment: "parent", scroll: false, drag: function(event, ui) {
I also created some code that permutes the handle to the location of any clicks in the parent div:
$(".Slider2d").mousedown(function(event){
What I would like to do is change the method described above so that the user can click somewhere in the parent div, move the handle to the click location and start dragging the handle without allowing the mouse button. Basically, I need to figure out a way to programmatically launch the drag and drop function.
I found several suggestions here and here , and tried to implement their recommendations by modifying the above like this:
$(".Slider2d").mousedown(function(event){ // get location of click and reposition handle to click location handle = $(".Slider2d").children(".Slider2dHandle"); handle.trigger(event); });
This works in the most technical sense, but its very slow, and I get a bunch of error messages from Safari telling me: "RangeError: Maximum call stack size." What I think is happening is that when I fire the event on the handle, it bubbles up to the parent, which then calls the trigger again and so on and so forth. I tried to stop the bubble by throwing the .stopPropagation event into my code before and after calling .trigger (), but to no avail.
So, if anyone has any suggestions on how to get this job, I would really appreciate it. I have a backup plan here , but it seems to me unnecessarily complicated.
Thanks!
jquery jquery-ui jquery-ui-draggable
jkjenner
source share