By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

drag function problem

100+
P: 178
Hi all,

I am using the drag function below which is from http://dunnbypaul.net/js_mouse/

I don't quite understand the code but was wondering if anyone knows how you would alter this code to so that objects being moved move a specified amount of pixels each time. Really the same functionality as snap in the scriptalicious drag drop function.

heres the drag function snippet.
Expand|Select|Wrap|Line Numbers
  1. function drag(e) // parameter passing is important for NS family 
  2. {
  3.   if (dragobj)
  4.   {
  5.     elex = orix + (mousex-grabx);
  6.     eley = oriy + (mousey-graby);
  7.     dragobj.style.position = "absolute";
  8.     dragobj.style.left = (elex).toString(10) + 'px';
  9.     dragobj.style.top  = (eley).toString(10) + 'px';
  10.   }
  11.   update(e);
  12.   return false; // in IE this prevents cascading of events, thus text selection is disabled
  13. }
  14.  
Jul 23 '08 #1
Share this Question
Share on Google+
4 Replies


hsriat
Expert 100+
P: 1,654
Is it like you want the drag to be disabled after a particular maximum number of pixels or you want the div to move at least a particular minimum number of pixels on each drag?
Jul 27 '08 #2

100+
P: 178
I want they div to move in jumps of 25px
Jul 28 '08 #3

hsriat
Expert 100+
P: 1,654
Expand|Select|Wrap|Line Numbers
  1. function drag(e) // parameter passing is important for NS family 
  2. {
  3.   if (dragobj)
  4.   {
  5.     var jumpX = mousex - grabx;
  6.     var jumpY = mousey - graby;
  7.     jumpX = Math.floor(jumpX / 25) * 25;
  8.     jumpY = Math.floor(jumpY / 25) * 25;
  9.     elex = orix + jumpX;
  10.     eley = oriy + jumpY;
  11.     dragobj.style.position = "absolute";
  12.     dragobj.style.left = (elex).toString(10) + 'px';
  13.     dragobj.style.top  = (eley).toString(10) + 'px';
  14.   }
  15.   update(e);
  16.   return false; // in IE this prevents cascading of events, thus text selection is disabled
  17. }
  18.  
See if this works.
Jul 28 '08 #4

100+
P: 178
Thanks that worked. Much appreciated
Jul 30 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.