Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: rollover effect with text


Message #1 by "Chung" <s9708970@y...> on Wed, 14 Feb 2001 13:25:06
Chung,

Try the code below. It should work in IE 5 (and 4 too I believe). However
neither of the two methods used will work in Netscape.

Method 1:
- Use the IE style "A:hover". This style is applied to an anchor <A> link
when the mouse hovers over it.

Method 2:
- Use the "onmouseover" and "onmouseout" events to call javascript
functions. The javascript functions modify the style property of the text.
Below I use event.srcElement to obtain an ID to the text object. The text ID
could be used instead, but the code would not be as generic (or "reusable").


Hope this helps,
Anil

Sevina Technologies
www.Sevina.com



================== CUT HERE =============================
<HTML>
<HEAD>
<STYLE>
A:hover{COLOR:red; TEXT-DECORATION: none}
A{COLOR: #00008b}
</STYLE>
<SCRIPT language=javascript>
function highlight()
{
 var oObj = event.srcElement
 oObj.style.color = "#FF00FF" ;
 oObj.style.textDecoration = "underline" ;
}

function lolight()
{
 var oObj = event.srcElement
 oObj.style.color = "#008000" ;
 oObj.style.textDecoration = "none" ;
}
</SCRIPT>
</HEAD>
<BODY>
<A href="mypage.html">Link Using a:hover CSS style</A>
<BR><BR><BR>
<DIV id=o style="color:#008000;" onmouseover="highlight()"
onmouseout="lolight()">Javascript style modification</DIV>
</BODY>
</HTML>

=================== END CUT ============================


----- Original Message -----
From: "Chung" <s9708970@y...>
To: "javascript" <javascript@p...>
Sent: Wednesday, February 14, 2001 1:25 PM
Subject: [javascript] rollover effect with text


> Hi there,
>      I was just wondering if it is possible to get a roller effect on a
> text with javascript. I'm after the exact popular effect that many do with
> jpgs, and gifs. However, with just text. What I want is to make a text
> change color when a mouse is over it.
>
>    I was also wondering, if it is possible to make an
> un-underlined text-link change color and underlined simultaneously when a
> mouse is over it? If its possible, how am to do this ?
>
> Thanks heaps
>
> chung
>
>
>


  Return to Index