SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to function just once?

    hi all,

    i have here a script from dynamicdrive.com doing neon light effect on text. it's a non-stop function. how to change it to just funtion once, or maybe twice, then stop the funtion?

    also, is it possible to break the message into 2 lines?

    thanks very much!

    here's the script:
    Code:
    <script language="JavaScript1.2">
    
    var message="Welcome to Dynamic Drive!"
    var neonbasecolor="gray"
    var neontextcolor="yellow"
    var flashspeed=100  //in milliseconds
    
    ///No need to edit below this line/////
    
    var n=0
    if (document.all||document.getElementById){
    document.write('<font color="'+neonbasecolor+'">')
    for (m=0;m<message.length;m++)
    document.write('<span id="neonlight'+m+'">'+message.charAt(m)+'</span>')
    document.write('</font>')
    }
    else
    document.write(message)
    
    function crossref(number){
    var crossobj=document.all? eval("document.all.neonlight"+number) : document.getElementById("neonlight"+number)
    return crossobj
    }
    
    function neon(){
    
    //Change all letters to base color
    if (n==0){
    for (m=0;m<message.length;m++)
    //eval("document.all.neonlight"+m).style.color=neonbasecolor
    crossref(m).style.color=neonbasecolor
    }
    
    //cycle through and change individual letters to neon color
    crossref(n).style.color=neontextcolor
    
    if (n<message.length-1)
    n++
    else{
    n=0
    clearInterval(flashing)
    setTimeout("beginneon()",1500)
    return
    }
    }
    
    function beginneon(){
    if (document.all||document.getElementById)
    flashing=setInterval("neon()",flashspeed)
    }
    beginneon()
    
    
    </script>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,191
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    limit

    It always make me smirk to see a script that someone wants to modify and the modifcations involve the "no need to change this" part.
    Anyway, the easiest way to limit the times the script runs is to add a "flag" variable and increment it inside the function, testing for it's value to control if the function gets run. eg.
    var fllag = 0;

    if (flag < 1)
    {
    do stuff
    flag++;
    }
    To split the message try using \n where you want the line break to be.

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks Mittineague, you can tell i'm still a newbe.

    thanks for your help and the laugh !

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi again,

    i did this:
    var flag = 0;

    function beginneon(){
    if(flag<2)
    {
    if (document.all||document.getElementById)
    flashing=setInterval("neon()",flashspeed)
    }
    flag++;
    }

    beginneon()
    and the script did stop running after two rounds, but neon light focus on the last word forever! how to get rid of it?

    thanks

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there,

    please help solve this problem.

    i tried this:
    var flag = 0;
    function beginneon(){
    if (document.all||document.getElementById)
    flashing=setInterval("neon()",flashspeed)
    flag++;
    if(flag>2) {clearInterval(flashing);}
    }

    beginneon();
    still can not get rid of the neon effect on last word!

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,191
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    back to base color

    Since you want to have the script end with the text being the "basecolor" the easiest (if not the best) thing to do is simply copy the portion of script that does that
    HTML Code:
    for (m=0;m<message.length;m++)
    {
    	//eval("document.all.neonlight"+m).style.color=neonbasecolor
    	crossref(m).style.color=neonbasecolor;
    }
    just put that in an "else" in the beginneon() function and it should work.
    Not neccessarily a second "if", otherwise when the flag is incremented it will "short" the last neon effect.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •