[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 08-25-2003, 08:21 AM   #1 (permalink)
NamePros Member
 
Join Date: Jul 2003
Posts: 120
185.00 NP$ (Donate)

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, 09:34 AM   #2 (permalink)
NamePros Member
 
Join Date: Jun 2003
Posts: 105
171.00 NP$ (Donate)

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, 10:26 AM   #3 (permalink)
NamePros Member
 
Join Date: Jul 2003
Posts: 120
185.00 NP$ (Donate)

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" ;
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, 10:44 AM   #4 (permalink)
NamePros Member
 
Join Date: Jun 2003
Posts: 105
171.00 NP$ (Donate)

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, 05:49 PM   #5 (permalink)
NamePros Member
 
Join Date: Jul 2003
Posts: 120
185.00 NP$ (Donate)

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

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


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:52 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85