JavaScript
- setInterval (<function>, 5000); // unit is milliseconds
- setTimeout (<function>, 5000);
- clearInterval (handler);
- clearTimeout (handler);
Example
var myImage = document.getelementById("mainImage"); var imageArray = ["_images/overlook.jpg", "_images/tree.pg",...] var imageIndex = 0; function changeImage() { myImage.setAttribute ("src", imageArray[imageIndex]); imageIndex++; if (imageIndex >= imageArray.length) { imageIndex = 0; } } var intervalHandle = setInterval (changeImage, 5000); myImage.onclick = function() { clearInterval (intervalHandler); }
Java
No comments:
Post a Comment