Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for mouseover.....!?

Status
Not open for further replies.

nexius

Programmer
Jul 8, 2000
109
CA
Hi
How do I check if the mouse is over a certain image?

putting it in the form of an if statement would be nice.

if mouse position = [over my image] {

blah

}

Really appreciate it if someone could help. THANKS.
-NeXius
 
inside your img tag place the onmouseover attribute with the call to the function that will handle the mouseover event, e.g.
Code:
<img src=&quot;yourImg.gif&quot; onmouseover=&quot;yourFunc()&quot;>

and in the <HEAD> of your page define yourFunc(), e.g.
Code:
<head>
<script>
function yourFunc()
{
 alert(&quot;don't put mouse over this image&quot;)
}
...

I hope this helped.
---
---
 
Yea, I know

And I do do that, but the script I need also demands another way of getting it.

I'm trying to make an animation button, so that a certain graphic continues to progress through certain frames, while the mouse is over the image, and then when the mouse falls back, it would decrease in frames...

See where I'm going with this?

Thanks anyway though --- and if someone else could help...?
-NeXius
 
Hi NeXius,

I think the better for you is tu use the &quot;event&quot; object.
There's a lot of properties like event.type, event.layerX, event.layerY ....

Hope this helps ...
 
You could write a series of functions to handle the animation, and then call the appropriate function on the onMouseOver & onMouseOut events ...
Code:
<IMG SRC=&quot;myimage.jpg&quot; onMouseOver=&quot;startAnim()&quot; onMouseOut=&quot;stopAnim()&quot;>
Something like that?

Greg.

 
&quot;I'm trying to make an animation button, so that a certain graphic continues to progress through certain frames, while the mouse is over the image, and then when the mouse falls back, it would decrease in frames...&quot;

The way you described it, I think it would be more appropriate to use Flash animation. Are you familiar with it? ---
---
 
Hi guys,

Yea I worked something together, it looks pretty cool... However, there's still a problem with the animation.

I did what Greg suggested (thanks man) but now for some reason it flashes in and out of picture
could somebody please check it out?

(I can't very effectively explain it)

go to
slowly and carefully move your mouse over one of the buttons, then slowly off again. Otherwise it becomes really screwed up.

THANK YOU.

-NeX
 
Not sure, but at first glance it looks like you have spaces in your image names, i.e. (from your code)

mem.src=&quot;frames/mem &quot; + i + &quot;.gif&quot;;

I would at first suggest getting rid of all these as it's generally not good practise, although it's probably not the main problem. Looking in the &quot;frames&quot; directory I see that is the case.

Secondly there are an awful lot of images to load which seems to take an age to load ... maybe someone can help with the specifics of that.

The theory behind it all is good though :)

Greg.
 
I wanted to do something similiar and I figured it out. What I wanted was one animation that started an effect, and second animation that looped when the mouse was over a button, and then a closing animation when the mouse left. I think this is what you wanted to do. Here is the code to make it work. This code could be stream lined, but I wanted to get it working first.

This goes in script

function MainButtonOver()
{
if (event.type == 'mouseover')
{
MainOverStartAni();
setTimeout(&quot;MainOverStillAni()&quot;,1600);
}
}

'This is the starting animation.
function MainOverStartAni()
{
changeImages('TopLeft', 'images/Top-Left.gif', 'TopCenter', 'images/Top-Center.gif', 'KaosImage', 'images/Kaos-Image.gif', 'MainButton', 'images/Main-Button-over.gif', 'BioButton', 'images/Bio-Button.gif', 'LinksButton', 'images/Links-Button.gif'); return true;
}

'This is the looping animation.
function MainOverStillAni()
{
changeImages('TopLeft', 'images/Top-Left.gif', 'TopCenter', 'images/Top-Center.gif', 'KaosImage', 'images/Kaos-Image.gif', 'MainButton', 'images/Main-Button-overstill.gif', 'BioButton', 'images/Bio-Button.gif', 'LinksButton', 'images/Links-Button.gif'); return true;
}


In the Body
<TD>
<A HREF=&quot;#&quot;
ONMOUSEOVER=MainButtonOver();
ONMOUSEOUT=&quot;changeImages('TopLeft', 'images/Top-
left.gif', 'MainButton', 'images/Main-Button-
out.gif'); return true;&quot;>

<IMG NAME=&quot;MainButton&quot; SRC=&quot;images/Main-Button.gif&quot; WIDTH=235 HEIGHT=84 BORDER=0>
</A>
</TD>

-David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top