Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Need to know if this is even possible (mouseover mayhem, long)

Reply
Thread Tools

Need to know if this is even possible (mouseover mayhem, long)

 
 
J. Makela
Guest
Posts: n/a
 
      09-20-2004
Hallo.

This should be a pretty entertaining question for you *real* javascript
writers.. I, being the lowly photoshop guy at an ad agency made the
mistake of actually saying "HTML" in a conversation once.. and now I
have been tasked with building a big website with LOTS of fancy
javascripting. Image rollovers mostly. Only problem is that I don't
really know how to do it. Of course, that's of no consequence so I have
to do it anyway. I've done simple mouseovers, but only for navigation
and stuff. Swapping out the actual image being moused over is relatively
easy.

But, one of the things I need to figure out is how to change 1 image
into 3 or 4 *different* images when OTHER parts of OTHER images are
moused over. It's very similar to a normal mouseover, except for the
fact that the image being moused over isn't the one changing. A
completely different picture at the bottom of the page needs to change.

Say there are 3 product names on the page (in an image, not copy or
text, so it'd be like an imagemap-type link). There is also a box at the
bottom that shows product 1 at the moment. But, when "Product 2" is
moused over in the main image, the box at the bottom has to change to
show Product 2. Same thing with Product 3. Is that even possible? I know
I've seen it before, but I don't know if it's javascripting that was
responsible. Is there a better CSS solution? Or was it built in Flash
and I'm in even more trouble than I think I am?



Second issue is an image mouseover that changes the color of *text* on
the page. They roll the pointer over a certain part of an image, and the
pertinent explanatory text *next* to the image needs to change color, as
well as having that particular part of the image change as well. Say I
slice a television JPG into 2 parts.. when you mouseover the screen, it
changes color AND some text to the right changes color to red. Doable
with a sliced-up image probably, but is it doable with actual text/copy?
The images/copy I've been given don't lend themselves to a simple image
rollover.



I know this is a pretty stupid post and I have no business meddling with
powers I don't understand.. the thing I need to know most is if this
stuff is even *possible*.. all the sample code I've found so far can
change text and images, but only the text and images being moused over..
I haven't found anything yet that can change one *separate* image into 3
different images based on mouseovers or change text colors based on an
image mouseover.

Any clues? Hints? Where to start (aside from jumping off a tall
buliding)? Kinda at the end of my rope here and was hoping somebody
could point me in the right direction. Thanks very much for any help you
guys can give, it is appreciated.


*heavy sigh*
J




 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      09-20-2004
"J. Makela" <(E-Mail Removed)> wrote in message
news:7TE3d.17987$wV.2386@attbi_s54...
> Hallo.
>
> This should be a pretty entertaining question for you *real* javascript
> writers.. I, being the lowly photoshop guy at an ad agency made the
> mistake of actually saying "HTML" in a conversation once.. and now I
> have been tasked with building a big website with LOTS of fancy
> javascripting. Image rollovers mostly. Only problem is that I don't
> really know how to do it. Of course, that's of no consequence so I have
> to do it anyway. I've done simple mouseovers, but only for navigation
> and stuff. Swapping out the actual image being moused over is relatively
> easy.
>
> But, one of the things I need to figure out is how to change 1 image
> into 3 or 4 *different* images when OTHER parts of OTHER images are
> moused over. It's very similar to a normal mouseover, except for the
> fact that the image being moused over isn't the one changing. A
> completely different picture at the bottom of the page needs to change.
>
> Say there are 3 product names on the page (in an image, not copy or
> text, so it'd be like an imagemap-type link). There is also a box at the
> bottom that shows product 1 at the moment. But, when "Product 2" is
> moused over in the main image, the box at the bottom has to change to
> show Product 2. Same thing with Product 3. Is that even possible? I know
> I've seen it before, but I don't know if it's javascripting that was
> responsible. Is there a better CSS solution? Or was it built in Flash
> and I'm in even more trouble than I think I am?
>
>
>
> Second issue is an image mouseover that changes the color of *text* on
> the page. They roll the pointer over a certain part of an image, and the
> pertinent explanatory text *next* to the image needs to change color, as
> well as having that particular part of the image change as well. Say I
> slice a television JPG into 2 parts.. when you mouseover the screen, it
> changes color AND some text to the right changes color to red. Doable
> with a sliced-up image probably, but is it doable with actual text/copy?
> The images/copy I've been given don't lend themselves to a simple image
> rollover.
>
>
>
> I know this is a pretty stupid post and I have no business meddling with
> powers I don't understand.. the thing I need to know most is if this
> stuff is even *possible*.. all the sample code I've found so far can
> change text and images, but only the text and images being moused over..
> I haven't found anything yet that can change one *separate* image into 3
> different images based on mouseovers or change text colors based on an
> image mouseover.
>
> Any clues? Hints? Where to start (aside from jumping off a tall
> buliding)? Kinda at the end of my rope here and was hoping somebody
> could point me in the right direction. Thanks very much for any help you
> guys can give, it is appreciated.
>
>
> *heavy sigh*
> J
>



Will this help for the first part?

Test "as-is"; watch for word-wrap.

<html>
<head>
<title>onmouse.htm</title>
</head>
<body>
<img src="http://www.google.com/images/logo.gif"
border="0" width="276" height="110" usemap="#google">
<br>
<img src="http://www.denijsdesign.de/dd_images/i_allg/xtrans_x_320x320.gif"
border="0" width="320" height="320" alt="" name="img">
<map name="google">
<area shape="RECT" coords="0,0,68,109"
onmouseover="javascriptnmouse('G')" onmouseout="onmouse('')" alt="G">
<area shape="RECT" coords="69,0,116,109"
onmouseover="javascriptnmouse('O')" onmouseout="onmouse('')" alt="O">
<area shape="RECT" coords="117,0,161,109"
onmouseover="javascriptnmouse('O')" onmouseout="onmouse('')" alt="O">
<area shape="RECT" coords="162,0,204,109"
onmouseover="javascriptnmouse('G')" onmouseout="onmouse('')" alt="G">
<area shape="RECT" coords="205,0,225,109"
onmouseover="javascriptnmouse('L')" onmouseout="onmouse('')" alt="L">
<area shape="RECT" coords="226,0,275,109"
onmouseover="javascriptnmouse('E')" onmouseout="onmouse('')" alt="E">
</map>
<script type="text/javascript">
var save = document.getElementById("img").src;
function onmouse(what) {
var pict;
if (what != "") {
pict = "http://www.outdoordecorcentral.com/graphics/BA07L91";
pict += what.toUpperCase() + ".jpg";
} else {
pict = save;
}
document.getElementById("img").src = pict;
}
</script>
</body>
</html>


 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      09-20-2004
On Mon, 20 Sep 2004 19:04:24 GMT, McKirahan <(E-Mail Removed)> wrote:

[snip]

> <img src="http://www.google.com/images/logo.gif"
> border="0" width="276" height="110" usemap="#google">
> <br>
> <img
> src="http://www.denijsdesign.de/dd_images/i_allg/xtrans_x_320x320.gif"
> border="0" width="320" height="320" alt="" name="img">


[snip]

> var save = document.getElementById("img").src;


[snip]

Interesting. So where is this element, 'img'?

Mike


Please trim quotes.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      09-20-2004
"Michael Winter" <(E-Mail Removed)> wrote in message
newspsem3ofcgx13kvk@atlantis...
> On Mon, 20 Sep 2004 19:04:24 GMT, McKirahan <(E-Mail Removed)> wrote:
>
> [snip]
>
> > <img src="http://www.google.com/images/logo.gif"
> > border="0" width="276" height="110" usemap="#google">
> > <br>
> > <img
> > src="http://www.denijsdesign.de/dd_images/i_allg/xtrans_x_320x320.gif"
> > border="0" width="320" height="320" alt="" name="img">

>
> [snip]
>
> > var save = document.getElementById("img").src;

>
> [snip]
>
> Interesting. So where is this element, 'img'?
>
> Mike
>
>
> Please trim quotes.
>
> --
> Michael Winter
> Replace ".invalid" with ".uk" to reply by e-mail.


"img" is the name assigned at the end of the following tag:

<img src="http://www.denijsdesign.de/dd_images/i_allg/xtrans_x_320x320.gif"
border="0" width="320" height="320" alt="" name="img">



Here's a version that highlights text on mouseover.

<html>
<head>
<title>onmouse.htm</title>
</head>
<body>
<img src="http://www.google.com/images/logo.gif"
border="0" width="276" height="110" usemap="#google">
<pre>
<br><span id="tx1">Google's 1st letter.</span>
<br><span id="tx2">Google's 2nd letter.</span>
<br><span id="tx3">Google's 3rd letter.</span>
<br><span id="tx4">Google's 4th letter.</span>
<br><span id="tx5">Google's 5th letter.</span>
<br><span id="tx6">Google's 6th letter.</span>
</pre>
<img src="http://www.denijsdesign.de/dd_images/i_allg/xtrans_x_320x320.gif"
border="0" width="320" height="320" alt="" name="img">
<map name="google">
<area shape="RECT" coords="0,0,68,109"
onmouseover="javascriptnmouse('tx1','G')" onmouseout="onmouse('tx1','')"
alt="G">
<area shape="RECT" coords="69,0,116,109"
onmouseover="javascriptnmouse('tx2','O')" onmouseout="onmouse('tx2','')"
alt="O">
<area shape="RECT" coords="117,0,161,109"
onmouseover="javascriptnmouse('tx3','O')" onmouseout="onmouse('tx3','')"
alt="O">
<area shape="RECT" coords="162,0,204,109"
onmouseover="javascriptnmouse('tx4','G')" onmouseout="onmouse('tx4','')"
alt="G">
<area shape="RECT" coords="205,0,225,109"
onmouseover="javascriptnmouse('tx5','L')" onmouseout="onmouse('tx5','')"
alt="L">
<area shape="RECT" coords="226,0,275,109"
onmouseover="javascriptnmouse('tx6','E')" onmouseout="onmouse('tx6','')"
alt="E">
</map>
<script type="text/javascript">
var save = document.getElementById("img").src;
function onmouse(parm,what) {
var pict;
if (what != "") {
colo = "yellow";
pict = "http://www.outdoordecorcentral.com/graphics/BA07L91";
pict += what.toUpperCase() + ".jpg";
} else {
colo = "white";
pict = save;
}
document.getElementById("img").src = pict;
document.getElementById(parm).style.background = colo;
}
</script>
</body>
</html>


 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      09-20-2004
McKirahan wrote:

<--snip-->

>
> "img" is the name assigned at the end of the following tag:
>
> <img src="http://www.denijsdesign.de/dd_images/i_allg/xtrans_x_320x320.gif"
> border="0" width="320" height="320" alt="" name="img">


Yes, but you try to access it using getElementByID, which is looking for
an *ID*. The fact it works in IE only means IE is getting it wrong.

> Here's a version that highlights text on mouseover.


No, its a version that works in IE, and no other browser I tested it in.

<--snip-->

> <area shape="RECT" coords="0,0,68,109"
> onmouseover="javascriptnmouse('tx1','G')" onmouseout="onmouse('tx1','')"
> alt="G">


The javascript:, AFAIK, is not needed there.

> document.getElementById("img").src = pict;


Here, you are trying to access an image with the name="img", yet the img
tag has no ID attribute, hence it fails in non-IE browsers. This is but
one error code produced by Mozilla:

Error: document.getElementById("img") has no properties
Source File:
file:///C:/Documents%20and%20Settings/Randy/My%20Documents/onmouse.htm
Line: 50

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      09-21-2004
"Randy Webb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> McKirahan wrote:
>
> <--snip-->
>
> >
> > "img" is the name assigned at the end of the following tag:
> >
> > <img

src="http://www.denijsdesign.de/dd_images/i_allg/xtrans_x_320x320.gif"
> > border="0" width="320" height="320" alt="" name="img">

>
> Yes, but you try to access it using getElementByID, which is looking for
> an *ID*. The fact it works in IE only means IE is getting it wrong.
>
> > Here's a version that highlights text on mouseover.

>
> No, its a version that works in IE, and no other browser I tested it in.
>
> <--snip-->
>
> > <area shape="RECT" coords="0,0,68,109"
> > onmouseover="javascriptnmouse('tx1','G')"

onmouseout="onmouse('tx1','')"
> > alt="G">

>
> The javascript:, AFAIK, is not needed there.
>
> > document.getElementById("img").src = pict;

>
> Here, you are trying to access an image with the name="img", yet the img
> tag has no ID attribute, hence it fails in non-IE browsers. This is but
> one error code produced by Mozilla:
>
> Error: document.getElementById("img") has no properties
> Source File:
> file:///C:/Documents%20and%20Settings/Randy/My%20Documents/onmouse.htm
> Line: 50
>
> --
> Randy
> comp.lang.javascript FAQ - http://jibbering.com/faq


Try this though I only tested it under IE.

<html>
<head>
<title>unchecks.htm</title>
<script type="text/javascript">
function checkonly(what) {
var form = document.fruitform;
for (var i=0; i<form.elements.length; i++) {
if (form.elements[i].type == "checkbox") {
if (what == 0) {
if (form.elements[i].value != "0") {
if (form.elements[i].name != what) {
form.elements[i].checked = false;
}
}
} else {
if (form.elements[i].value == "0") {
form.elements[i].checked = false;
}
}
}
}
}
</script>
</head>
<body>
<form name="fruitform" action="..." method="post">
<input type="checkbox" value="1" name="fruit" onclick="checkonly('1')">
Apples
<input type="checkbox" value="2" name="fruit" onclick="checkonly('2')">
Oranges
<input type="checkbox" value="3" name="fruit" onclick="checkonly('3')">
Pears
<input type="checkbox" value="0" name="fruit" onclick="checkonly('0')"> No
Answer
</form>
</body>
</html>


 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      09-21-2004
[snip]

> Try this though I only tested it under IE.
>
> <html>
> <head>
> <title>unchecks.htm</title>


Please ignore my last response as it was for another post.


 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      09-21-2004
On Mon, 20 Sep 2004 20:00:19 GMT, McKirahan <(E-Mail Removed)> wrote:

> "Michael Winter" <(E-Mail Removed)> wrote in message
> newspsem3ofcgx13kvk@atlantis...


[snip]

>> Mike
>>
>>
>> Please trim quotes.
>>
>> --
>> Michael Winter
>> Replace ".invalid" with ".uk" to reply by e-mail.


Don't include signatures when quoting someone else's post. A good
newsreader will remove them for you.

> "img" is the name assigned at the end of the following tag:
>
> <img
> src="http://www.denijsdesign.de/dd_images/i_allg/xtrans_x_320x320.gif"
> border="0" width="320" height="320" alt="" name="img">


You missed my point entirely. You identify that element by name, yet you
use the getElementById method. Surely, common sense tells you something is
wrong with that.

I've mentioned before that using getElementById should only be used when
appropriate collections are not available. In this case, use the
document.images collection. It will retrieve images identified by both id
and name (ids checked first).

It pays you to test everything in a decent browser, rather than IE. Once
things are fine in Opera and Mozilla, then check with IE.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
J. Makela
Guest
Posts: n/a
 
      09-21-2004
Wow, lots of good help here.. between this and some other stuff I found,
I think I *might* be able to muddle my way through. Pray for me.

Thanks very much!
J

 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      09-21-2004
On Mon, 20 Sep 2004 17:58:27 GMT, J. Makela <(E-Mail Removed)> wrote:

[snip]

> Swapping out the actual image being moused over is relatively easy.


Extremely easy. See:

<URL:http://www.mlwinter.pwp.blueyonder.co.uk/image-swap/>

> But, one of the things I need to figure out is how to change 1
> image into 3 or 4 *different* images when OTHER parts of OTHER images
> are moused over. It's very similar to a normal mouseover, except for the
> fact that the image being moused over isn't the one changing. A
> completely different picture at the bottom of the page needs to change.


There's no problem here, but if the swapped-in image is important, make
sure it can be accessed even if Javascript is disabled. The easiest way to
assure this is to place the images within links.

function replaceImage(fN, iN) {
document.images[iN].src = fN;
}

<a href="first-large.jpg"
onmouseover="replaceImage(this.href,'mainImg');">
<img src="first.jpg" alt=""></a>

<a href="second-large.jpg"
onmouseover="replaceImage(this.href,'mainImg');">
<img src="second.jpg" alt=""></a>

<a href="third-large.jpg"
onmouseover="replaceImage(this.href,'mainImg');">
<img src="third.jpg" alt=""></a>

<img name="mainImg" id="mainImg" src="first-large.jpg" alt="">

[snip]

> Second issue is an image mouseover that changes the color of *text* on
> the page.


Can you show the structure of this particular section of HTML? It might be
usable as is, or you might need to restructure it.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU Usage frequently 100% even though it seems not even close tototal memory Newcomer Computer Support 3 11-15-2009 06:51 AM
CPU Usage frequently 100% even though it seems not even close tototal memory Newcomer Computer Support 0 11-14-2009 11:21 PM
Why my working ps/2 mouse freezes and even don't even get recon.after reboot ? demi General Computer Support 0 08-03-2007 05:30 AM
Why my working ps/2 mouse freezes and even don't even get recon.after reboot ? demi General Computer Support 0 08-03-2007 05:28 AM
Even older fart, even newer newbie Stan Goodman Java 11 07-04-2003 07:32 AM



Advertisments