Hi andrew,

try this code, I think it will do what you want:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    <title>test divers</title>
    <script src="prototype.js" type="text/javascript"></script>
    <script src="scriptaculous.js" type="text/javascript"></script>

<div id="log"></div>
<div id="elm" style="width:100px;height:100px;background-color:blue"></

var LastPos=[0,0];
new Draggable('elm', { snap: [50, 50], onDrag: function() {
   // Run this every 50 pixels...
   var pos=$('elm').viewportOffset();
   if(pos[0]===LastPos[0] && pos[1]===LastPos[1]) return false;
    //this code will execute only if the snap value change
} });


For the bonus question, you'll have the contrain parameter:
"constraint: string, not set by default. If set to 'horizontal' or
'vertical' the drag will be constrained to take place only
horizontally or vertically."
But I don't think it's what you really want !

But with some (simple:) modification, previous function can tell you
the direction the element is moved.


On 10 fév, 05:39, Andrew <luckyd...@gmail.com> wrote:
> Hello, I'm wondering if there's any way to have the onDrag function
> execute only when the "snap" happens, for instance:
> new Draggable('el', { snap: [50, 50], onDrag: function() {
>    # Run this every 50 pixels...
> } });
> Bonus question: Is there any way to tell what direction the element is
> being dragged in (to the top, to the left, etc.)? Thank you!
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to