473,408 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

drag function problem

178 100+
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
4 1239
hsriat
1,654 Expert 1GB
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
cleary1981
178 100+
I want they div to move in jumps of 25px
Jul 28 '08 #3
hsriat
1,654 Expert 1GB
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
cleary1981
178 100+
Thanks that worked. Much appreciated
Jul 30 '08 #5

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

Similar topics

9
by: Wang, Jay | last post by:
Hello, all, I would like to enable some text between <SPAN url="http://www.testserver.com/">WORD TO BE DRAGGED </SPAN>. I put some javascript and it will extract http://www.testserver.com/ from...
1
by: Ryan Stewart | last post by:
If you don't want to read this post because of its length, I understand. I've spent two and a half days on this problem and have a good deal of information to relate. And this is kind of a long...
5
by: simon_s_li | last post by:
Hi, I have 5 fields in line where I need to drag and drop the text from one field to another field and then all the fields need to re-order themselves. So for instance if I drag the text in...
8
by: ericgorr | last post by:
I have the following test page: http://ericgorr.net/test.html <html> <head><title>Simple JavaScript</title></head> <BODY ondragstart="alert(event.srcElement.tagName)"> <INPUT TYPE=text...
1
by: sujithegr8 | last post by:
HIii... Its me sujith i've done something with AJAX. but for the rest i need someo ones help.. i've done half the work. there are two tables. "ajax1" and "ajax2" (check db.sql)
2
by: vunet.us | last post by:
Hello JavaScript experts, I have a floating div which I drag all over the page. If the page has scrollbars and users drag the floating div to the very top, page scrolls up too. The problem occurs...
1
by: kidelectric | last post by:
The issue I am having is that I would like to be able to drag-and-drop div elements that have rounded corners.* Since these elements will be dynamically created (including background color), I could...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.