Image Rollovers

This is a discussion on "Image Rollovers" within the JavaScript Forum section. This forum, and the thread "Image Rollovers are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 31st, 2007, 08:18
Junior Member
Join Date: Jun 2007
Location: Warsaw, IN
Age: 21
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DDock3287 Send a message via MSN to DDock3287 Send a message via Yahoo to DDock3287 Send a message via Skype™ to DDock3287
Image Rollovers

Well, I just started venturing into JavaScript. Now that I'm halfway through the book [JavaScript Bible 5th Ed.] I decided to try to do some stuff. But like always - my scripts are not working. Here is the code in my rollover.js file
Code: Select all
// JavaScript Document

//Precache of "Off" Button Images
var offImgArray = new Array();
offImgArray["addon"] = new Image(100,30);
offImgArray["calendar"] = new Image(100,30);
offImgArray["forums"] = new Image(100,30);
offImgArray["gallery"] = new Image(100,30);
offImgArray["home"] = new Image(100,30);
offImgArray["photos"] = new Image(100,30);
offImgArray["tslogin"] = new Image(100,30);
offImgArray["updates"] = new Image(100,30);

//Off Image Array
offImgArray["addon"].src = "http://www.webforumz.com/images/linkies/1addons.jpg";
offImgArray["calendar"].src = "http://www.webforumz.com/images/linkies/1calendar.jpg";
offImgArray["forums"].src = "http://www.webforumz.com/images/linkies/1forums.jpg";
offImgArray["gallery"].src = "http://www.webforumz.com/images/linkies/1gallery.jpg";
offImgArray["home"].src = "http://www.webforumz.com/images/linkies/1home.jpg";
offImgArray["photos"].src = "http://www.webforumz.com/images/linkies/1photos.jpg";
offImgArray["tslogin"].src = "http://www.webforumz.com/images/linkies/1tslogin.jpg";
offImgArray["updates"].src = "http://www.webforumz.com/images/linkies/1update.jpg";

//Precache of "On" Button Images
var onImgArray = new Array();
onImgArray["addon"] = new Image(100,30);
onImgArray["calendar"] = new Image(100,30);
onImgArray["forums"] = new Image(100,30);
onImgArray["gallery"] = new Image(100,30);
onImgArray["home"] = new Image(100,30);
onImgArray["photos"] = new Image(100,30);
onImgArray["tslogin"] = new Image(100,30);
onImgArray["updates"] = new Image(100,30);

//On Image Array
onImgArray["addon"].src = "http://www.webforumz.com/images/linkies/addonsparkle.gif";
onImgArray["calendar"].src = "http://www.webforumz.com/images/linkies/calendarsparkle.gif";
onImgArray["forums"].src = "http://www.webforumz.com/images/linkies/forumsparkle.gif";
onImgArray["gallery"].src = "http://www.webforumz.com/images/linkies/gallerysparkle.gif";
onImgArray["home"].src = "http://www.webforumz.com/images/linkies/homesparkle.gif";
onImgArray["photos"].src = "http://www.webforumz.com/images/linkies/photosparkle.gif";
onImgArray["tslogin"].src = "http://www.webforumz.com/images/linkies/tsloginsparkle.gif";
onImgArray["updates"].src = "http://www.webforumz.com/images/linkies/updatesparkle.gif";


//Swap Functions
function imageOn(imgName)
{
    if (document.images)
    {document.images[imgName].src = onImgArray[imgName].src;}
}
function imageOff(imgName)
{
    if (document.images)
    {document.images[imgName].src = offImgArray[imgName].src;}
}
In my header I have this call for the rollover.js file.

Code: Select all
<script type="text/javascript" src="rollover.js"></script>
And this is how I have my image on my page linked as...

Code: Select all
<a href="index.html" onmouseover="imageOn('home')" onmouseout="imageOff('home')">
        <img border="0" src="http://www.webforumz.com/images/linkies/1home.jpg" alt="Home" /></a>
Anyone see any problems? It is basically out of the book as they show it, but I have placed the preloading code into an external document, as this will be used for all my links.

Thanks, DDock

Last edited by DDock3287; Aug 1st, 2007 at 16:38.
Reply With Quote

  #2 (permalink)  
Old Jul 31st, 2007, 10:39
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: Image Rollovers

Going by your description above, shouldnt the include of the javascript read:-
Code: Select all
<script type="text/javascript" src="rollover.js"></script>
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
  #3 (permalink)  
Old Jul 31st, 2007, 10:42
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: Image Rollovers

... I presume the file is referenced properly but you mentioned rollover.js as the filename.

Try changing the image alt text to all lower case.... javascript is CaSe SeNsItIvE
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
  #4 (permalink)  
Old Jul 31st, 2007, 13:43
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Image Rollovers

Hmmm ... I would use CSS for this

Pure CSS rollovers without Javascript
Reply With Quote
  #5 (permalink)  
Old Jul 31st, 2007, 23:42
Junior Member
Join Date: Jul 2007
Location: Sydney
Age: 26
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Image Rollovers

Have to agree that CSS would be best. The best rollover technique in my opinion is this:

http://www.alistapart.com/articles/slidingdoors2/
Reply With Quote
  #6 (permalink)  
Old Aug 1st, 2007, 01:48
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Image Rollovers

^ which basically originated from this

Fast Rollovers Without Preload


Reply With Quote
  #7 (permalink)  
Old Aug 1st, 2007, 16:37
Junior Member
Join Date: Jun 2007
Location: Warsaw, IN
Age: 21
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DDock3287 Send a message via MSN to DDock3287 Send a message via Yahoo to DDock3287 Send a message via Skype™ to DDock3287
Re: Image Rollovers

Quote:
Originally Posted by Rob View Post
Going by your description above, shouldn't the include of the javascript read:-
Code: Select all
<script type="text/javascript" src="rollover.js"></script>
Yes, I did end up changing that, but not in my code script I placed here. Ill look into the css image rollovers - I'd honestly want to do that anyways. CSS is something I know a bit better. Thanks

Ok I looked at the CSS Rollover Images. Would it be easy to put an animated GIF as the secondary. It would seem I would have to have both as an animated GIF for it to work. Wouldn't that end up making the file size a bit larger?

Essentially the rollover image will be the same as the first one, but the "shield" on the button will be sparkling.

Last edited by DDock3287; Aug 1st, 2007 at 16:44.
Reply With Quote
  #8 (permalink)  
Old Aug 1st, 2007, 16:49
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Image Rollovers

No animated gif need. It's just flat image with both state. I explain it quite clearly I think in my blog (the first link I posted)
Reply With Quote
  #9 (permalink)  
Old Aug 2nd, 2007, 04:18
Junior Member
Join Date: Jun 2007
Location: Warsaw, IN
Age: 21
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DDock3287 Send a message via MSN to DDock3287 Send a message via Yahoo to DDock3287 Send a message via Skype™ to DDock3287
Re: Image Rollovers

The Second image I want to be an animated Gif. Sorry if I was unclear.
Reply With Quote
  #10 (permalink)  
Old Aug 2nd, 2007, 12:06
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Image Rollovers

Ok well ... that doesn't matter ... you just add it the same way!? The non-animated on top and the animated at the bottom.
Reply With Quote
  #11 (permalink)  
Old Aug 3rd, 2007, 08:09
Junior Member
Join Date: Jun 2007
Location: Warsaw, IN
Age: 21
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DDock3287 Send a message via MSN to DDock3287 Send a message via Yahoo to DDock3287 Send a message via Skype™ to DDock3287
Re: Image Rollovers

Karinne, Just to let you know, the first site you linked is now closed. Just wanted to let you know.
Reply With Quote
  #12 (permalink)  
Old Aug 3rd, 2007, 11:40
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Image Rollovers

Yeah ... I know ... it's my blog! I closed it down Sorry ... the second link is basically the same
Reply With Quote
  #13 (permalink)  
Old Aug 7th, 2007, 22:55
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 147
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to ScottR Send a message via Skype™ to ScottR
Re: Image Rollovers

I agree with everyone else but I'll take a shot in the dark here. Does the book have it listed with the word this in front of the argument in the onmouseover and onmouseout event?

It seems to me that the script may need to know what object the function is referring to.

Just a guess from having a quick glance at the script.

Also your book should have a website with all the scripts available for download. You can DL it and check it against yours.

Good Luck,
Scott
Reply With Quote
  #14 (permalink)  
Old Aug 16th, 2007, 16:04
Junior Member
Join Date: Jun 2007
Location: Warsaw, IN
Age: 21
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DDock3287 Send a message via MSN to DDock3287 Send a message via Yahoo to DDock3287 Send a message via Skype™ to DDock3287
Re: Image Rollovers

Thanks for everyone that assisted me. I have successfully implemented the CSS rollovers.
Reply With Quote
  #15 (permalink)  
Old Aug 16th, 2007, 18:57
Up'n'Coming Member
Join Date: Jul 2007
Location: Glasgow
Age: 15
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Image Rollovers

Could we see it.
Reply With Quote
Reply

Tags
image rollover preloading

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image Rollovers and CMS Raid JavaScript Forum 8 Oct 25th, 2007 07:50
Hyperlink Rollovers crackafaza Web Page Design 3 Aug 24th, 2007 11:43
Image Rollovers DDock3287 Web Page Design 12 Aug 14th, 2007 21:23
faded rollovers benbramz Graphics and 3D 7 Aug 30th, 2005 15:28
ImageReady rollovers gwx03 Graphics and 3D 9 Jul 6th, 2004 07:48


All times are GMT. The time now is 00:06.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43