Introduction:-
In this tutorial I will show you how to change the image when the user puts the cursor over an image and then change it back when the user puts the cursor away from the image.
Solution:-
Make These Two Functions Between The <head> tags:-
And Make This code between the <body> Tags:-Code:<SCRIPT language="JavaScript"> if (document.images) { img1on= new Image(100,100); img1on.src="img2.jpg"; img1off= new Image(100,100); img1off.src="img1.jpg"; } function change(imgName) { if (document.images) { imgOn=eval(imgName + "on.src"); document[imgName].src= imgOn; } } function changeback(imgName) { if (document.images) { imgOff=eval(imgName + "off.src"); document[imgName].src= imgOff; } } </SCRIPT>
Save your work and add these 2 images into your directory to see the effectCode:<A onMouseover="change('img1')" onMouseout="changeback('img1')"> <IMG SRC="img1.jpg" name="img1" width="100" height="100"></A>
Explanation:-
You think it is needed? I think its self explanatory. But if you have any problems.. just ask![]()
A Preview:-
Conclusion:-
As Always Feedback is welcome and the full source is attached!!
Last edited by TcM; 12-03-2006 at 10:30 AM.
it's cool ... thank you...
Very good tutorial, nice for a web site.
i need help with understanding this portion of the code.Code:if (document.images) { img1on= new Image(100,100); img1on.src="img2.jpg"; img1off= new Image(100,100); img1off.src="img1.jpg"; }![]()
It is creating a new image that is 100x100 (size) and the src is img2.jpg. Similar to saying:
HTML Code:<img src="img2.jpg" width="100" height="100">
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks