NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Mouseover buttons (JavaScript)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-25-2003, 09:21 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Jul 2003
Posts: 118
web guru is an unknown quantity at this point
 



Mouseover buttons (JavaScript)


Just want some advice - am making some mouse over buttons and I have written some JavaScript code for it. But it is very slow to display the mousover image. Can any one give me some advice on how to speed it up or another way of doing mouse overs.

PS. I have already made the images as small as possible.
web guru is offline  
Old 08-25-2003, 10:34 AM   #2 (permalink)
NamePros Member
Join Date: Jun 2003
Posts: 103
Fallout_Multi. is an unknown quantity at this point
 



<img border=0 name="image" src="image1.jpg" onMouseOver="image.src='image2.jpg'" onMouseOut="image.src='image1.jpg'">

In your code, put the above on one line. The first time you try it, the picture needs to load so it might lag for a second. I recommend using a preloader if you have more than a few rollovers. "image" is the name of your picture. image1 is the picture when the page loads, image2 is your picture with the mouse over it, and it goes back to image1 after you take your mouse off. Change the code in bold to your names. Hope this works for you!
__________________
http://www.falloutweb.com
Fallout_Multi. is offline  
Old 08-25-2003, 11:26 AM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Jul 2003
Posts: 118
web guru is an unknown quantity at this point
 



I already have this done here is my code:

--------------------------

<script language="JavaScript" type="text/javascript">

if (document.images) {
//Preload Image

homeOne = new Image();
homeOne.src = "images/homeOne.gif" ;
????: NamePros.com http://www.namepros.com/programming/15169-mouseover-buttons-javascript.html
homeTwo = new Image() ;
homeTwo.src = "images/homeTwo.gif" ;


}

function buttondown( buttonname )
{
if (document.images) {
document[ buttonname ].src = eval(buttonname + "Two.src" );
}
}
function buttonup ( buttonname )
{
if (document.images) {
document[ buttonname ].src = eval(buttonname + "One.src" );
}
}

-----------------------

And

-----------------------

<a href="http://www.banaghergaa.com" onMouseOver="buttondown('home')"
onMouseOut="buttonup('home')">

<img src="images/homeOne.gif" name="home" width="72" height="17" border="0"></a>

-----------------------
web guru is offline  
Old 08-25-2003, 11:44 AM   #4 (permalink)
NamePros Member
Join Date: Jun 2003
Posts: 103
Fallout_Multi. is an unknown quantity at this point
 



Try this for each image, remember to change the name and the image names:

<a href="http://www.banaghergaa.com" onMouseOver="home.src='images/homeTwo.gif'"
onMouseOut="home.src='images/homeOne.gif'">

<img src="images/homeOne.gif" name="home" width="72" height="17" border="0"></a>

*EDIT* needed the image/ path for the pics
__________________
http://www.falloutweb.com
Fallout_Multi. is offline  
Old 08-25-2003, 06:49 PM THREAD STARTER               #5 (permalink)
NamePros Member
Join Date: Jul 2003
Posts: 118
web guru is an unknown quantity at this point
 



ok I have made your suggested change to the code but I am now trying to preload the images using the following code,

---------------------------

function doPreload()
{

var the_images = new Array('images/contactOne.gif','images/contactTwo.gif',
'images/faqTwo.gif', 'images/faqOne.gif', 'images/aboutusOne.gif', 'images/aboutusTwo.gif',
'images/portfolioOne.gif', 'images/portfolioTwo.gif', 'images/productsOne.gif', 'images/productsTwo.gif',
'images/hostingOne.gif', 'images/hostingTwo.gif', 'images/servicesOne.gif', 'images/servicesTwo.gif',
'images/homeOne.gif', 'images/homeTwo.gif');
preloadImages(the_images);
}

function preloadImages(the_images_array) {

for(var loop = 0; loop < the_images_array.length; loop++)

{
var an_image = new Image();
an_image.src = the_images_array[loop];
}
}

---------------------------

and I call the preLoad() function in the body tag, but it doesent seem to be preloading the images right as every time I do a mouse over the browser starts to dowload the image. Heres an example of a mouse over button code

---------------------------

<a href="http://www.banaghergaa.com" onMouseOver="home.src='images/homeTwo.gif';" onMouseOut="home.src='images/homeOne.gif';">

<img src="images/homeOne.gif" name="home" width="72" height="17" border="0"></a>

---------------------------


I think it might have sometink to do with the line

an_image.src = the_images_array[loop];

but am not sure
web guru is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:48 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger