Author Topic: Javascript mousetest  (Read 2676 times)

0 Members and 1 Guest are viewing this topic.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Javascript mousetest
« on: April 01, 2012, 02:47:44 pm »
Well, I got this problem with javascript, I have to test if the mouse is over a element, but it must be in a if-condition.
Somehow this doesn't work: if (!document.getElementById('buttons').onmouseover)
Please help me!

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Javascript mousetest
« Reply #1 on: April 01, 2012, 02:50:03 pm »
if (!document.getElementById('buttons').onmouseover) tests if the onmouseover property of #buttons is defined, not whether it's triggered or not. Basically, it tests if the browser is going to do something when the user mouses over.
« Last Edit: April 01, 2012, 02:50:29 pm by Deep Thought »




Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Javascript mousetest
« Reply #2 on: April 01, 2012, 03:52:51 pm »
Ah, I get that. How do I do then what I really want?

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Javascript mousetest
« Reply #3 on: April 01, 2012, 06:27:10 pm »
You could have onmouseover set a variable and onmouseout unset it.
Kind of like what was suggested here: http://www.sitepoint.com/forums/showthread.php?572033-Determine-if-mouse-is-over-an-element
I'll look around and see if there is a simpler way.

If you want to do a lot of tests I'm sure there is a way you can use this: http://www.permadi.com/tutorial/cssGetElementUnderMouse/index.html
« Last Edit: April 01, 2012, 06:29:01 pm by Eeems »
/e