Solved

OnMouseover display random image

Posted on 1997-07-09
1
322 Views
Last Modified: 2011-10-03
Hi there,

I have a small JAVA applet running at
http://www.infonie.fr/public_html/germann/Index.htm     (please check),
the mouseover effect is used to display gif files at random.
Is it possible to do the same thing with JAVASCRIPT ?

(Note: the Java applet on my page works fine with Netscape3 but doesn't
work with N4)

Thanks,

Juan
germann@infonie.fr
0
Comment
Question by:Jgermann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
Trevor013097 earned 50 total points
ID: 1268397
Yes it is possible to do exactly the same thing in Javascript.First you must create an array of images which are preloaded and then a random function must pick one of these array entries at random (obviously!!) and then a simple onmouseover with an image displays the results.Here is how to do it:<HEAD>
<TITLE>Random Music</TITLE>
</HEAD>

<SCRIPT LANGUAGE="Javascript">

image1 = new Image();
image1.src = "image1.gif";
image2 = new Image();
image2.src = "image2.gif";
image3 = new Image();
image3.src = "image3.gif";
image4 = new Image();
image4.src = "image4.gif";

var imageArray = new makeArray('image1', 'image2', 'image3', 'image4');


function makeArray(){
this.length = makeArray.arguments.length
for (var i = 0; i < this.length; i++)
this[i + 1] = makeArray.arguments[i]
}

function randNum (num) {
var now = new Date();
var rand = Math.round(num * Math.cos(now.getTime()));
if (rand < 0) rand = - rand; if (rand == 0) rand++;
return rand;
}

var imgsrc = imageArray[randNum(imageArray.length)]

</SCRIPT>
</HEAD>
<BODY>


<A HREF="Your-page.html"
      onmouseover = "document.random.src = imgsrc"
      onmouseout = "document.random.src = imgsrc"
>
<IMG SRC="image1.gif" NAME=random BORDER=0></A>

</BODY>

</HTML>Hope this helps
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question