Hi andrew, try this code, I think it will do what you want:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>test divers</title> <script src="prototype.js" type="text/javascript"></script> <script src="scriptaculous.js" type="text/javascript"></script> </head> <body> <div id="log"></div> <div id="elm" style="width:100px;height:100px;background-color:blue"></ div> <script> 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 LastPos=pos; $('log').insert('<div>position:['+pos[0]+','+pos[1]+']</div>'); } }); </script> </body> </html> 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. -- david 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 prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---