Myside's Spew - Blog of Spontaneous Combustible Spew

Javascript Flash Text

10 August, 2011 04:19 CST6CDT

The HTML 'Blink' element is quickly making its way out of the web browser rendering engines.  IE (Internet Explorer) ignores this element and will only display the text you want flashing as a normal textual output with no decorations.

I put together an easy script which will modify a CSS DIV ID's text to flash on and off at an interval of your choosing using Javascript.  Here is the example:

<html>
<head>
<script type="text/javascript">
var i=0;
function flashtext() {
if(i%2==0)
{ var textcolours = 'black'; }
else
{ var textcolours = 'white'; }
document.getElementById( 'flashingtext' ).style.color = textcolours;
if(i<1)
{ i++; }
else
{ i-- }
}
setInterval( 'flashtext()', 500 );
</script>
</head>

<body>
<div id="flashingtext">this text will flash</div>
</body>
</html>

If you need to turn on or off the textual flashing using an OnClick type method, you may assign an ID to setInterval() and then clear that interval using clearInterval();  For example, remove "setInterval( 'flashtext()', 500 );" from the above Javascript and fill an <a> tag with "ft = setInterval( 'flashtext()', 500 );" to execute the flash function identified by 'ft', and then you may optionally clear the flashing text intervals with "clearInterval ( ft );" using the examples below:

<a href="javascript:void(0)" onclick="ft = setInterval( 'flashtext()', 500 );">on link</a>

<a href="javascript:void(0)" onclick="clearInterval ( ft );">off link</a>

A year ago I was writing...

Verbatim SOHO NAS (96436) Firmware Update
.88 miles of track on my map

Software  Projects  Article & Comments

Add a Comment

Verification (Required)
authimage
Your comment will appear once it is approved and
your e-mail address will NOT be shared

Main Entry:   spew   Pronunciation:   \ˈspyü\
Function: verb
Etymology: Middle English, from Old English spīwan; akin to Old High German spIwan to spit, Latin spuere, Greek ptyein   First Known Use: before 12th century

intransitive verb
  1. VOMIT
  2. to come forth in a flood or gush
  3. to ooze out as if under pressure : EXUDE
transitive verb
  1. VOMIT
  2. to send or cast forth with vigor or violence or in great quantity <a volcano spewing out ash> —often used with out —spew·er noun
Land where drunk cows swim and home to my daily hand