ThomasJSmart
Programmer
- Sep 16, 2002
- 634
Hi im looking for a way to make the scriptaculous dragdrop function snap to a grid aswell as stay inside a parent object.
seperatly this works:
Snap to grid:
constrain to parent:
but how to get them together?? if someone could give me a poke in the right direction it would be much apreciated..
I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
seperatly this works:
Snap to grid:
Code:
new Draggable( 'DDobject', {snap:[151,20]});
constrain to parent:
Code:
new Draggable('DDobject',{
snap: function(x,y,draggable) {
function constrain(n, lower, upper) {
if (n > upper) return upper;
else if (n < lower) return lower;
else return n;
}
element_dimensions = Element.getDimensions(draggable.element);
parent_dimensions = Element.getDimensions(draggable.element.parentNode);
return[
constrain(x, 0, parent_dimensions.width - element_dimensions.width),
constrain(y, 0, parent_dimensions.height - element_dimensions.height)
];
}
});
but how to get them together?? if someone could give me a poke in the right direction it would be much apreciated..
I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!