This is a migrated thread and some comments may be shown as answers.

Constrain dragging to the x or y axis

2 Answers 163 Views
Drag and Drop
This is a migrated thread and some comments may be shown as answers.
Gareth
Top achievements
Rank 1
Gareth asked on 25 Apr 2012, 10:02 AM
Hi all

Is it possible to constrain dragging to a particular x or y axis? Or, failing that, constrain it to a particular region? From the demo I can see that the drop area can be constrained, but it's the actual dragging (or its visualization) that I want to limit to a particular axis...

Thanks
G

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 26 Apr 2012, 09:27 AM
Hello Gareth,

You can use the drag event of the Kendo Draggable object, check the position of the mouse cursor (e.clientX, e.clientY) and reposition the drag hint (this.hint) manually. If you apply top and left styles directly, they will be overwritten immediately, that's why you need to use CSS classes with hard-coded coordinates and !important.

function draggableOnDrag(e) {
    if (true) //hint is too much to the right
    {
         this.hint.addClass("maxRight");
    }
    if (true) //hint is too much to the bottom
    {
         this.hint.addClass("maxBottom");
    }
}


.maxRight
{
     left: 400px !important;
}
 
.maxBottom
{
     top: 400px !important;
}


Using the above approach with 4 CSS classes (one for minLeft and one for minBottom) and applying one or two at a time, you can force the hint to remain within a certain area.

Greetings,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gareth
Top achievements
Rank 1
answered on 26 Apr 2012, 02:06 PM
Thanks, I'll try that out.
Tags
Drag and Drop
Asked by
Gareth
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Gareth
Top achievements
Rank 1
Share this question
or