Lissa Explains it All:  Web Design Forums  

Go Back   Lissa Explains it All: Web Design Forums > LEIA Archives > Web Site Help > JavaScript/DHTML

Notices

 
 
Thread Tools Display Modes
  #1  
Old 05-09-2004, 04:21 AM
PHP Guru PHP Guru is offline
n00bzilla
 
Join Date: May 2004
Posts: 38
PHP Guru is an unknown quantity at this point
emulate <blink> tag

I know some of you might know of its existance, however the <blink> tag does not work in Internet Explorer, and to my knowledge you cannot control its time intervals. Hopefully this little script will prove worthy:

It should just go in your header:
Code:
<script type="text/javascript">
<!--
// interval length (in seconds)
var intervalLength = .5;
function emulateBlink() {
 objs = document.getElementsByTagName("span");
 for(x = 0; x < objs.length; x++) {
  if(objs[x].getAttribute("blink") == "blink") {
   if(objs[x].style.visibility == "hidden") {
	objs[x].style.visibility = "visible";
   } 
   
   else {
	objs[x].style.visibility = "hidden";
   }
  }
 }
 window.setTimeout("emulateBlink();",(intervalLength * 1000));
}
if(document.getElementsByTagName) {
 emulateBlink();
}
-->
</script>
Basically, in order to use it, just do something like this:
Code:
<span blink="blink">this is blinking text!</span>
And that's it

I didn't think this should go in user submitted tutorials, simply because it isn't really a tutorial, it's just a javascript. But if you think it must belong there, then feel free to do what you think is best
  #2  
Old 05-09-2004, 02:04 PM
Calidris Calidris is offline
Script Kiddie
 
Join Date: Apr 2004
Location: UK
Posts: 158
Calidris is an unknown quantity at this point
Slight problem... there's no such thing as a blink attribute so it wouldn't validate against any W3C standards. Using class="blink" would be more appropriate
__________________
<html onload="fix_my_errors(please);">
  #3  
Old 05-09-2004, 03:17 PM
PHP Guru PHP Guru is offline
n00bzilla
 
Join Date: May 2004
Posts: 38
PHP Guru is an unknown quantity at this point
I thought of that... and now I can't justify why I didn't do that... lol. I will alter the script

For some reason, when using the class attribute, it does not work. However, when I plugin the id attribute, it works just as expected. However, if you wanted more than one blinking thing, it would be politically incorrect to use that ID twice. So I decided to just use the name attribute instead.

Here's the new script, since I cannot edit my old post:
Code:
<script type="text/javascript">
<!--
// interval length (in seconds)
var intervalLength = .5;
function emulateBlink() {
objs = document.getElementsByTagName("span");
for(x = 0; x < objs.length; x++) {
if(objs[x].getAttribute("name") == "blink") {
if(objs[x].style.visibility == "hidden") {
	objs[x].style.visibility = "visible";
} 
 
else {
	objs[x].style.visibility = "hidden";
}
}
}
window.setTimeout("emulateBlink();",(intervalLength * 1000));
}
if(document.getElementsByTagName) {
emulateBlink();
}
-->
</script>
And you would want to use this to get something to blink:
Code:
<span name="blink">Blinking stuff</span>
  #4  
Old 05-09-2004, 10:26 PM
Calidris Calidris is offline
Script Kiddie
 
Join Date: Apr 2004
Location: UK
Posts: 158
Calidris is an unknown quantity at this point
The name of an element is also a unique identifier, only used to group objects in the context of an HTML form (e.g. radio buttons have the same name).

To get the class of an element you should use element.className and also note the annoying fact that some people might have two class names, so you would have to split the className up by spaces and check if any of the given class names match "blink" (or I've seen the same effect done with regexp too).

I was curious and ran a little experiment to see how simply using <blink> tags effects your script (and making IE apply itself). This works just fine, although Mozilla will do a double-blink kind of effect due to trying to apply two different blink styles (the built in one and your script). To fix this you could surround your script in IE conditional comments *shrugs* I'm just bored, can you tell? lol
__________________
<html onload="fix_my_errors(please);">
  #5  
Old 05-09-2004, 10:42 PM
PHP Guru PHP Guru is offline
n00bzilla
 
Join Date: May 2004
Posts: 38
PHP Guru is an unknown quantity at this point
Quote:
Originally Posted by Calidris
The name of an element is also a unique identifier, only used to group objects in the context of an HTML form (e.g. radio buttons have the same name).

To get the class of an element you should use element.className
Good call
Code:
<script type="text/javascript">
<!--
// interval length (in seconds)
var intervalLength = .1;
function emulateBlink() {
 objs = document.getElementsByTagName("span");
 for(x = 0; x < objs.length; x++) {
  if(objs[x].className == "blink") {
   if(objs[x].style.visibility == "hidden") {
	objs[x].style.visibility = "visible";
   } 
   
   else {
	objs[x].style.visibility = "hidden";
   }
  }
 }
 window.setTimeout("emulateBlink();",(intervalLength * 1000));
}
if(document.getElementsByTagName) {
 emulateBlink();
}
-->
</script>
And...
Code:
<span class="blink">something</span>
Quote:
and also note the annoying fact that some people might have two class names, so you would have to split the className up by spaces and check if any of the given class names match "blink" (or I've seen the same effect done with regexp too).
Instead of...
Code:
<span class="blink red green">
You would use:
Code:
<span class="blink"><span class="red green">
It's the responsibility of the coder to write it like that ...

Quote:
I was curious and ran a little experiment to see how simply using <blink> tags effects your script (and making IE apply itself). This works just fine, although Mozilla will do a double-blink kind of effect due to trying to apply two different blink styles (the built in one and your script). To fix this you could surround your script in IE conditional comments *shrugs* I'm just bored, can you tell? lol
If you were using this script, why would you use it in conjunction with the <blink> tag? Also, with the <blink> tag you can't specify intervals
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:09 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.