SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2000
    Location
    France
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a series of small pics that when you rollover, I would like them to be replaced with a new random one (and stay as the new image, until next rollover).

    Any help much appreciated!

  2. #2
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know much about javascript, but i bet you just have to do something like OnMouseOver="javascript:randomscript()" .
    Then in the < HEAD > section, put your random image javascript function (here called "randomscript").

    Hope this helps
    [blogger: zengun] [blogware contributor: wordpress]

  3. #3
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's one way to do it:


    <html>
    <head>
    <title>Untitled</title>

    <script language="JavaScript">
    <!--

    function randomImage() {
    pic = new Array();
    pic[0] = 'little_dude.gif';
    pic[1] = 'grower.gif';
    pic[2] = 'scrubz.gif';

    randomNum = Math.floor(Math.random()*pic.length);
    newImage = 'images/' + pic[randomNum];
    return newImage;
    }

    // -->
    </script>
    </head>

    <body>

    <img name="myImage" src="images/little_dude.gif" onMouseOver="this.src = randomImage();"><br>
    <img name="myImage2" src="images/grower.gif" onMouseOver="this.src = randomImage();"><br>
    <img name="myImage3" src="images/scrubz.gif" onMouseOver="this.src = randomImage();"><br>

    </body>
    </html>

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2000
    Location
    France
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Doesn't seem to work

    Thanks for the reply scrubz. I've tried as you suggested, but it doesn't seem to work. What do you think is wrong?
    http://www.bigdeepblue.com/dev/domin...llovertest.htm

    (all the paths to gifs are correct)

    Thanks.

  5. #5
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the second to the last line in the script...

    newImage = 'images/' + pic[randomNum];

    to

    newImage = pic[randomNum];

    The way it was written, it was assuming that images were always in an 'images' directory, but since you're defining the full path of your images...

    pic[0] = '../testsite/smallpics/maracca2.jpg'; )

    you don't need to point to an 'images' directory. Hope this works for you.

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2000
    Location
    France
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    It works

    Excellent! Thanks scrub.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •