Forum Moderators: open

Message Too Old, No Replies

onmouseover issue (changing text color)

onmouseover issue

         

jonwald

9:46 am on Apr 14, 2005 (gmt 0)

10+ Year Member



I have a simple piece of javascript to change the color of a piece of text when the mouse moves over it. The text also links to another page, which opens a new browser window. Problem is, only the left half of the text recognises the onmouseover command. When I move the mouse over the right half of the text, nothing happens. Anyone encountered anything like this before?

Thanks,

Jonathan

birdbrain

10:28 am on Apr 14, 2005 (gmt 0)



Hi there jonwald,

and a warm welcome to these forums. ;)

To help resolve this problem, we really need to see all the relevant code.

birdbrain

jonwald

6:35 am on Apr 15, 2005 (gmt 0)

10+ Year Member



Hi Birdbrain thanks for the welcome! I wasn't sure about the protocol of posting code, so I thought I'd wait and see if it was requested. But since it is, here goes. I've tried it 2 ways: one where all links change color, and one where just the specific link in question changed color. Both tries had the same effect: the link in layer 6 only changed color when the mouse went over the left half. The other links, by the way, changed color in a more predictable way. Thanks in advance for your help.

The single line attempt is:

<DIV id="layer6">

<DIV class="dynamic-style-3">
<SPAN class="dynamic-style-4"> <a onMouseOver="this.style.color='#FF7B1F'" onMouseOut="this.style.color='#000000'" onclick="window.open('Comedy Program.htm','jonathanwald.com','left=20,top=20,width=630,height=630');"style="text-decoration: none">Comedy of Errors</a><BR></DIV></SPAN>

The complete page is below, with an alternate way of programming the color change:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<HTML>

<HEAD>
<META name="generator" content="Adobe InDesign HTML Export Plug-in">
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE>Noises Off</TITLE>

<SCRIPT LANGUAGE="JavaScript">

var num=1
img1 = new Image ()
img1.src = "images/noises-small-1.jpg"
img2 = new Image ()
img2.src = "images/noises-small-2.jpg"
img3 = new Image ()
img3.src = "images/noises-small-3.jpg"
img4 = new Image ()
img4.src = "images/Noises-Small-4.jpg"

text1 = "Text for Picture One"
text2 = "Text for Picture Two"
text3 = "Text for Picture Three"
text4 = "Text for Picture Four"

function slideshowUp()
{
num=num+1
if (num==5)
{num=1}
document["theatrestill"].src=eval("img"+num+".src")
document.jon.wald.value=eval("text"+num)
}

function slideshowBack()
{
num=num-1
if (num==0)
{num=4}
document["theatrestill"].src=eval("img"+num+".src")
document.jon.wald.value=eval("text"+num)
}

</SCRIPT>

<STYLE type="text/css">
<!--
#layer1 {position: absolute; top: 87px; left: 239px; height: 189px; width: 209px; padding: 0px; margin: 0px; z-index: 1}
#layer2 {position: absolute; top: 489px; left: 740px; height: 81px; width: 77px; padding: 0px; margin: 0px; z-index: 2}
#layer3 {position: absolute; top: 390px; left: 725px; height: 102px; width: 89px; padding: 0px; margin: 0px; z-index: 3}
#layer4 {position: absolute; top: 368px; left: 58px; height: 197px; width: 156px; padding: 0px; margin: 0px; z-index: 4}
#layer5 {position: absolute; top: 376px; left: 74px; height: 52px; width: 157px; padding: 0px; margin: 0px; z-index: 5}
#layer6 {position: absolute; top: 430px; left: 59px; height: 156px; width: 155px; padding: 0px; margin: 0px; z-index: 6}
#layer7 {position: absolute; top: 34px; left: 198px; height: 70px; width: 87px; padding: 0px; margin: 0px; z-index: 7}
#layer8 {position: absolute; top: 3px; left: 140px; height: 458px; width: 600px; padding: 0px; margin: 0px; z-index: 8}
#layer9 {position: absolute; top: 470px; left: 59px; height: 156px; width: 155px; padding: 0px; margin: 0px; z-index: 9}
#layer10 {position: absolute; top: 490px; left: 62px; height: 156px; width: 155px; padding: 0px; margin: 0px; z-index: 10}
.dynamic-style-1 {font-family: 'Gill Sans'; font-size: 36px; line-height: 55px; color: #FFFFFF;}
.dynamic-style-2 {font-family: 'Times'; font-size: 28px; line-height: 33px; color: #000000}
.dynamic-style-3 {text-align: center}
.dynamic-style-4 {font-family: 'Gill Sans'; font-size: 28px; line-height: 20px; color: #000000; font-variant: small-caps}
.dynamic-style-5 {font-family: 'Gill Sans'; font-size: 20px; line-height: 12px; color: #000000; font-variant: small-caps}
.dynamic-style-6 {font-family: 'Gill Sans'; font-size: 30px; line-height: 10px; color: #FF7B1F}
.dynamic-style-7 {font-family: 'Gill Sans'; font-size: 26px; line-height: 24px; color: #000000; font-variant: small-caps}
.DIVDefaultParaStyle {text-align: left}
.DefaultParaStyle {font-family: 'Times'; font-size: 12px; line-height: 14px; color: #000000}
A:link {text-decoration: none; color:black}
A:visited {text-decoration: none; color:black}
A:hover {text-decoration: none; color:#FF7B1F}
-->
</STYLE>

</HEAD>

<BODY link="black" alink="black" vlink="black">

<DIV id="layer1">
<IMG border="0" height="189" width="209" src="images/Noises-Small-1.jpg" NAME="theatrestill" alt="noises 1">
</DIV>

<DIV id="layer2">
<a href="Jonathan Wald Home.htm" style="Text-decoration: none"> <IMG border="0" height="71" width="67" src="images/Monopoly House.jpg" alt=""></a>
</DIV>

<DIV id="layer3">
<a href="Theater Main.htm" style="Text-decoration: none"> <IMG border="0" height="102" width="89" src="images/theatre-chairs.jpg" alt="image23.jpg"></a>
</DIV>

<DIV id="layer4">
<IMG border="0" height="197" width="156" src="images/theatre-prog-blank.jpg" alt="prog-blank.jpg">
</DIV>

<DIV id="layer5">

<DIV class="DIVDefaultParaStyle">
<SPAN class="dynamic-style-1">Program</SPAN><SPAN class="dynamic-style-2"><BR></SPAN>
</DIV>

</DIV>

<DIV id="layer6">

<DIV class="dynamic-style-3">
<SPAN class="dynamic-style-4"> <a onclick="window.open('From Stiller Program.htm','left=20,top=20,width=630,height=630');"style="text-decoration: none">Noises Off!</a><BR></DIV></SPAN>
</DIV>
<DIV id="layer9">
<DIV class="dynamic-style-3">
<SPAN class="dynamic-style-6">Photos<BR></SPAN>
</DIV>
</DIV>

<DIV id="layer10">
<DIV class="dynamic-style-3"><SPAN class="dynamic-style-7"> <A HREF="JavaScript:slideshowBack()"style="text-decoration: none"> back</A>

<A HREF="JavaScript:slideshowUp()"style="text-decoration: none"> next</A>
<BR></SPAN>
</DIV>

</DIV>

<DIV id="layer7">
<IMG border="0" height="70" width="87" src="images/image46.gif" alt="white">
</DIV>

<DIV id="layer8">
<IMG border="0" height="478" width="600" src="images/drapes transparent 2.png" alt="stage">
</DIV>

</BODY>
</HTML>

natty

9:35 am on Apr 15, 2005 (gmt 0)

10+ Year Member



hi jonwald,

a couple of things,

firstly i would opt for changing the styles via

element.className = "some style in your stylesheet" - (note the capital N in className)
rather than setting the color directly.

also the bit abou the text only working on the left word..
i pasted your page into a doc then loaded it up, obviously i dont have your images or anything, but it was easier to see that the reason the rh text is not doing anything is because .. i think .. it is covered by the layer 8 layer.

maybe setting the z-index of the covered layer to higher will pop it to the top and make the text work..

just a thought, might be worth a go.

gl
hth

nat

Bernard Marx

11:14 am on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



firstly i would opt for changing the styles via

element.className = "some style in your stylesheet" - (note the capital N in className)
rather than setting the color directly.

I disagree (respectfully). Dynamically switching/amending className is a very flexible way of doing things, but it can have it's own complications. Considering that only one property is being changed, I don't think it's worth it - on balance.

This is because jonwald will have to either

a) Define a whole new CSS rule restating all the other properties that are in the initial class.

b) Use specific functions to deal with adding and removing individual classes from a multiple-className attribute.

Bernard Marx

11:35 am on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



natty's right about it being obscured by a layer.

Add this rule to the stylesheet:

div{border: solid 1px red;}

and you'll see what's going on.

jonwald

1:45 pm on Apr 15, 2005 (gmt 0)

10+ Year Member



Thanks for all the advice. I fixed it using your help - though not exactly in the way expected. The layer issue seemed clear after I outlined in red - but the problem continued even after I moved the layer that cut off half the text. However, when I changed the z-index of the layer with the link so that it was highest, the problem was fixed.

Thanks again for the assistance. I have another question about slideshows on multiple pages, but I'll post that elsewhere.

Cheers,

Jonathan

natty

8:58 pm on Apr 15, 2005 (gmt 0)

10+ Year Member



i must remember to prefix personally rather than firstly. just easier to sort out on multiple pages..
but then again, i'd always listen to bernard i cant even begin to count the amount of times he has helped me out..
:-)