Old 05-09-2006, 12:29   #1 (permalink)
captainK
Registered User
 
captainK's Avatar
 
Join Date: Dec 2005
Location: Leeds
Posts: 56
Javascript quick fix

Can anyone tell me why this bit of Javscript isn't working in Firefox (works fine in IE).

I'm using it to work out the mouse position.

Code:
function getMouseXYPos(e) { var mouseX = 0; var mouseY = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { mouseX = e.pageX; mouseY = e.pageY; } if (e.clientX || e.clientY) { mouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; mouseY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } document.getElementById('productPopUp').style.left = mouseX; document.getElementById('productPopUp').style.top = mouseY; return true; }//end function

Cheers guys
  Reply With Quote
Old 06-09-2006, 10:11   #2 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,130
Not sure exactly what's wrong with that, but this works

Code:
document.getElementById('id').onmousemove=function(e) { var blah = mousepos(e); alert(blah.x); alert(blah.y); }; function mousepos(e) { var x = 0; var y = 0; if (window.event) { x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } else { x = e.clientX; y = e.clientY; } return({x:x,y:y}); }
__________________
George Smith - a vain attempt to get higher on google for my name

  Reply With Quote
Old 11-09-2006, 04:11   #3 (permalink)
captainK
Registered User
 
captainK's Avatar
 
Join Date: Dec 2005
Location: Leeds
Posts: 56
Hm thanks for that Stickmus but it doesn't seem to work. You can see the code at work here: thedarkangel.co.uk/catalogue3.php?c=2

Last edited by captainK : 14-09-2006 at 12:01.
  Reply With Quote
Old 12-09-2006, 06:21   #4 (permalink)
captainK
Registered User
 
captainK's Avatar
 
Join Date: Dec 2005
Location: Leeds
Posts: 56
Resolved!

Needed to add px to the end of the values:

Code:
document.getElementById('productPopUp').style.left = mouseX+"px"; document.getElementById('productPopUp').style.top = mouseY+"px";
  Reply With Quote
Old 12-09-2006, 13:12   #5 (permalink)
paulanthony
mingin dawg baitch
 
paulanthony's Avatar
 
Join Date: Apr 2004
Location: Belfast
Posts: 1,035
Send a message via MSN to paulanthony
have you seen this?

http://boxover.swazz.org/
  Reply With Quote
Old 14-09-2006, 11:59   #6 (permalink)
captainK
Registered User
 
captainK's Avatar
 
Join Date: Dec 2005
Location: Leeds
Posts: 56
Quote:
Originally Posted by paulanthony
have you seen this?

http://boxover.swazz.org/


Cheers for that. Looks useful.
  Reply With Quote
Old 21-09-2006, 20:12   #7 (permalink)
f00
Registered User
 
Join Date: Sep 2006
Posts: 2
IE specific

document.body used below is IE specific.

Quote:
Originally Posted by captainK
Can anyone tell me why this bit of Javscript isn't working in Firefox (works fine in IE).

I'm using it to work out the mouse position.

Code:
function getMouseXYPos(e) { var mouseX = 0; var mouseY = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { mouseX = e.pageX; mouseY = e.pageY; } if (e.clientX || e.clientY) { mouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; mouseY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } document.getElementById('productPopUp').style.left = mouseX; document.getElementById('productPopUp').style.top = mouseY; return true; }//end function

Cheers guys
  Reply With Quote
Old 28-10-2006, 10:19   #8 (permalink)
Suigeneriz
Norwegian Viking™
 
Join Date: Oct 2006
Location: Norway
Posts: 55
Code:
function getMouseXYPos(e) { var mouseX = 0; var mouseY = 0; if (!e) var e = (window.event) // IE; if (e.pageX || e.pageY) { mouseX = e.pageX; mouseY = e.pageY; } else if (e.clientX || e.clientY) // Netscape/Firefox/Opera { mouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; mouseY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } document.getElementById('productPopUp').style.left = mouseX; document.getElementById('productPopUp').style.top = mouseY; return true; }//end function
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8