Solved

OnMouseover display random image

Posted on 1997-07-09
1
315 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ckeditor not working on textarea created by javascript function 5 48
javascript delete path 7 44
Jquery Calculation 3 41
Javascript Error 10 24
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. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

738 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