javascript mouseover and out functions

Hamza

I have got a problem in the mouseover and out functions other than that it works. What i mean when the mouse is over the image the image should stop but when the mouse is out the same interval should take place.

thank you for your help.

var myImage = document.getElementById("world");

    var imageArray = ["imgs/worldGray.png","imgs/worldGreen.png","imgs/worldPink.png", "imgs/worldYellow.png", "imgs/world.png"];//html picture add here
    var imageIndex=0;


    function changeImage(){
        myImage.setAttribute("src",imageArray[imageIndex]);
        imageIndex++;
        if(imageIndex >=imageArray.length){
            imageIndex =0;
        }
    }
    var intervalHandle=setInterval(changeImage,5000);
    // the problem is in the below fucntions
    myImage.onmouseover = function(){
        clearInterval(intervalHandle);
    }
    myImage.onmouseout = function(){
        setInterval(intervalHandle);
    }
Ali Naci Erdem

I'm not shure why you are setting the interval again using the "intervalHandler", and don't think there is such a use.

http://www.w3schools.com/jsref/met_win_setinterval.asp

You should write

intervalHandle=setInterval(changeImage,5000);

inside onmouseout handler to make it run correctly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related