PDA

View Full Version : make an image flash


RHolm
05-27-2004, 04:11 AM
Hey all,

I have a form on a website i'm making, and when the user selects "Unsure" in the drop-down menu, i want an image to flash 3 times, is that possible in Javascript, and if so, can someone please point me in the right direction?

Thanks

Ryan

skidooer
05-27-2004, 07:24 PM
Remember, flashing elements are annoying. Don't abuse it.

<script type="text/javascript">
var image = new Array(2);

function initFlash() {
var img = document.getElementById("flashImage");
image[0] = img.getAttribute("altsrc");
image[1] = img.getAttribute("src");
}

function doFlash(count, speed) {
if(count == undefined) count = 3;
if(speed == undefined) speed = 400;
doFlashLoop(count * 2, speed);
}

function doFlashLoop(count, speed) {
if(count) {
document.getElementById("flashImage").src = image[count % 2];
setTimeout("doFlashLoop(" + (count - 1) + ", " + speed + ")", speed);
}
}
</script>
<body onload="initFlash()">
image1.jpg
</body>

RHolm
05-27-2004, 07:31 PM
thanks heaps, skidooer