473,387 Members | 3,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,387 software developers and data experts.

Why won't the following work in FireFox?

I have the following code which allows you to drag a div in IE, and have it
then move back to it's natural position when you release the mouse button:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><script type="text/javascript">var draggable=0;</script></head>
<body>
<div id="div1"
style="width:300px;height:300px;background-color:orange;"></div>
<div id="div2" style="width:300px;height:300px;background-color:green;"
onmousedown="draggable=1;this.style.position='abso lute';this.style.left=event.x-25+'px';this.style.top=event.y-25+'px';"
onmousemove="if(draggable==1){this.style.left=even t.x-25+'px';this.style.top=event.y-25+'px';}"
onmouseup="draggable=0;this.style.position='static ';"></div>
</body>
</html>
I have written what I would expect to do the same thing in other browsers (I
replaced event.x/event.y with event.layerX/event.layerY). Here is that code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><script type="text/javascript">var draggable=0;</script></head>
<body>
<div id="div1"
style="width:300px;height:300px;background-color:orange;"></div>
<div id="div2" style="width:300px;height:300px;background-color:green;"
onmousedown="draggable=1;this.style.position='abso lute';this.style.left=event.layerX-25+'px';this.style.top=event.layerY-25+'px';"
onmousemove="if(draggable==1){this.style.left=even t.layerX-25+'px';this.style.top=event.layerY-25+'px';}"
onmouseup="draggable=0;this.style.position='static ';"></div>
</body>
</html>
However, when I attempt to drag the div in FireFox it just sort of "jumps
around", it definitely isn't doing what the IE version did in IE. did I do
something wrong? Was there something that should have been in both of the
versions that I forgot? Any help would be appreciated. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Oct 17 '07 #1
2 1647
heres my version ...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">
var draggable=0;

function onMDown(e) {
e = e || window.event;
var el = e.target || e.srcElement;
draggable=1;
el.style.position='absolute';
el.style.left=( e.x || e.clientX )-25+'px';
el.style.top=( e.y || e.clientY )-25+'px';
}

function onMMove(e) {
e = e || window.event;
var el = e.target || e.srcElement;
if(draggable==1){
el.style.left=( e.x || e.clientX )-25+'px';
el.style.top=( e.y || e.clientY )-25+'px';
}
}

function onMUp(e) {
e = e || window.event;
var el = e.target || e.srcElement;
draggable=0;
el.style.position='static';
}
</script>
</head>
<body>
<div
id="div1"
style="width:300px;height:300px;background-color:orange;">
</div>
<div
id="div2"
style="width:300px;height:300px;background-color:green;"
onMouseDown="onMDown(event)"
onMouseMove="onMMove(event)"
onMouseUp="onMUp(event)">
</div>
</body>
</html>

D.
Oct 17 '07 #2
On Oct 17, 12:12 pm, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
I am using XHTML because the place where I will be using these techniques is
in an ASP.NET page, which is created using that header. The x/y properties
That seems an odd choice for a Microsoft product.
are only used in the IE version; both pageX/Y and clientX/Y gave an alert
saying they were undefined, so I did not know what else to use for IE. Is
The clientX/Y properties are certainly present in IE.
there something else that works in IE? I would like to skip the drag & drop,
but my boss won't let me.
There is some very simple cross-browser drag and drop code in this
project:

http://code.google.com/p/niceshowcase/

You will see that it only uses pageX/Y and clientX/Y.

Oct 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: aznFETISH | last post by:
I have had this on a page for a long time <span style="text-align:left;text-indent: 0em;line-height:12pt;font-family: futura, helvetica, arial, sans-serif;font-weight: normal;font-size:...
9
by: Roger Withnell | last post by:
Tearing hair out time! Simple attached page shows the problem. http://www.brilley.co.uk/TestFocusSelect.htm Using a function to test if too many characters have been keyed in to a textarea....
5
by: LRW | last post by:
(Sorry if this is a repost...my newsreader keeps crashing on the posting--I don't know if the message going out or not) For some reason this javascript just won't work in Firefox. It works fine...
7
by: Gary Kaucher | last post by:
At the top of the page on my website http://www.itemlook.com I have an animated gif called "eyeline.gif". It has worked fine in the past, but recently I am unable to get it to work using IE6. All...
4
by: stevong | last post by:
It works on Konquerer though. I remember it works on IE too. I've tried window.close() too. Doesn't work on Firefox also. I've also tried to create a function. It doesnt work on Firefox also....
4
by: petermichaux | last post by:
Hi, I'm hoping for a reason I'm wrong or an alternate solution... I'd like to be able to dynamically include some javascript files. This is like scriptaculous.js library but their solution is...
16
by: Rod | last post by:
I can't get this alert to show no matter what I do. Making me crazy. One doesn't equal two...does it? <html> <head> <title>Rider Survey</title> <link rel="stylesheet" type="text/css"...
2
by: Altman | last post by:
I have created an ascx control and I am calling registerclientscriptblock. The path to the js file is relative to the aspx page and not the ascx file. The function runs fine in IE7 but in...
4
by: mikeyfrombrighton | last post by:
Hi all, Strange thing. I want users to be able to go back to a list of products after they have looked at their shopping basket. Whilst in their shopping basket they may make edits etc so it's...
5
tjc0ol
by: tjc0ol | last post by:
Hi all, I made contact page which allows visitors to input their name, email address, phone number, comments and select a comment type by using <select> element in html with javascript. Among the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.