Blinking Images With Javascript

I needed to have an image blink in one of our intranet applications today, so I wrote this quick javascript to accomodate. There aren’t many good image blinker scripts online, so I’m adding mine to the mix:

Start by adding this to your javascript file:

function blinkId(id) {
	var i = document.getElementById(id);
	if(i.style.visibility=='hidden') {
		i.style.visibility='visible';
	} else {
		i.style.visibility='hidden';
	}
    setTimeout("blinkId('"+id+"')",1000);
	return true;
}

And this right before you end your <html> tag:

<script type="text/javascript">blinkId('YOUR_ELEMENT_ID');</script>

This will work for images, divs, spans, pretty much any block level element with an id.

Updated 8/19/2008: Fixed a copy/paste bug in this post.

  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Technorati
  • TwitThis
  • Google
  • Fark
  • Reddit
  • Furl
  • SphereIt
  • Pownce
  • E-mail this story to a friend!

If you liked this post, you might like these

3 Comments

Ivan says: 4 August 2008 at 3:47 pm

The correct is:
…..
setTimeout(”blinkId(’”+id+”‘)”,1000);
return true;
…..

Adam S says: 4 August 2008 at 3:53 pm
firsttube.com

Huh.. I typed it backwards. Obviously, I’m using the solution for real - the real code has it right. Not sure how I transposed it wrong.

Me says: 10 August 2008 at 7:49 am

I just pinched this code (knowing very little JS) and swore for a while because it wouldn’t work.

Copy and paste into TextMate resulting in some weird versions of apostrophes and quote marks, as if it was using smart quotes. I had to delete them all and retype them manually to get it to work.

Leave a comment

:   :   :


You can also create an account, if you'd like.