Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    clearinterval on onmouseout for a slideshow.

    I am trying to have a slide show of pictures that are randomly generated stop when the user mouses over the image, I have got everything to work so far except the onmouseover event, even the onmouseout seems to work I don't necessarily need the exact answer but any guidance would be appreciated!


    <script type="text/javascript">
    /* ! [CDATA[ */
    setInterval('randomImage()', 4000); //sets the interval of images to show every 4 seconds and runs the function to do so.

    var imgs = new Array("outdoors.jpg", "kayak.jpg", "fishing.jpg", "scuba.jpg", "biking.jpg"); //the array of images

    function randomImage() {
    document.getElementById("image").src = imgs[Math.floor(Math.random()*imgs.length)];
    }
    //the function calls for a random number and applies it to the array of images to show a random picture.
    /* ]]> */
    </script>
    </head>
    <body>
    <p>
    <img src="outdoors.jpg" width="200" height="200" alt="Random Image" id="image" onmouseover="clearInterval();" onmouseout="randomImage()" />
    </p>

    I am not quite sure what I am doing wrong I've tried mutliple different set ups for the "onmouseover="clearInterval();" and nothing seems to work.

  • #2
    New Coder
    Join Date
    Nov 2010
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I figured it out, actually a rather simple fix after I looked at it just set the interval to a variable. Thanks anyway codingforums ;P


  •  

    Posting Permissions

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