Jump to content

[SOLVED] Setting loop limit for text scroll script


9999

Recommended Posts

How could I set a scroll loop limit of 5 times for this scroll script so that it stops after 5 loops?

 

<script language=JavaScript1.2>
/* USE WORDWRAP AND MAXIMIZE THE WINDOW TO SEE THIS FILE
========================================
NewsBar v1.4
License : Freeware (Enjoy it!)
(c)2004 VASIL DINKOV- PLOVDIV, BULGARIA
========================================
For IE4+, NS4+, Opera7+ & Konqueror2+
========================================
Get the NewsBar script at:
http://www.smartmenus.org/other.php
and don't wait to get the Great SmartMenus script at:
http://www.smartmenus.org
LEAVE THESE NOTES PLEASE - delete the comments if you want */

// BUG in Opera:
// If you want to be able to control the body margins
// put the script right after the BODY tag, not in the HEAD!!!

// === 1 === FONT, COLORS, EXTRAS...
n_font='verdana,arial,sans-serif';
n_fontSize='11px';//10px originally
n_fontSizeNS4='12px';//11px originally
n_fontWeight='normal';
n_fontColor='#ffffff';
n_textDecoration='none';
n_fontColorHover='#ff0000';//		| won't work
n_textDecorationHover='underline';//	| in Netscape4
n_bgColor='#000000';//set [='transparent'] for transparent or use #000000
n_top=5;//100 originally	  |
n_left=20;//30 originally	  | defining
n_width=468;//500 originally      | the box
n_height=20;//14 originally       |
n_position='absolute';// absolute or relative
n_timeOut=5;//seconds
n_pauseOnMouseOver=true;
n_speed=50;//1000 = 1 second
n_leadingSign='';//originally was '_'
n_alternativeHTML='';//use www.smartmenus.org between qoutes or leave blank
// for not supported browsers like Opera<7 - usually
// you may want to put a link to your news page

// === 2 === THE CONTENT - ['href','text','target']
n_content=[
['','Welcome to the NewsBar example page!',''],
['http://www.smartmenus.org/','You can always get the latest version at: http://www.smartmenus.org/','_self'],
['http://www.smartmenus.org/','Or you may want to get the most advanced navigation system for your site?','_self']
];

// THE SERIOUS SCRIPT 
n_nS4=document.layers?1:0;
n_iE=document.all && !window.innerWidth && navigator.userAgent.indexOf("MSIE")!=-1?1:0;
n_nSkN=document.getElementById && (navigator.userAgent.indexOf("Opera")==-1 || document.body.innerHTML) && !n_iE?1:0;
n_t=0;
n_cur=0;
n_l=n_content[0][1].length;
n_timeOut*=1000;
n_fontSize2=n_nS4 && navigator.platform.toLowerCase().indexOf("win")!=-1?n_fontSizeNS4:n_fontSize;
document.write('<style>.nnewsbar,a.nnewsbar,a.nnewsbar:visited,a.nnewsbar:active{font-family:'+n_font+';font-size:'+n_fontSize2+';color:'+n_fontColor+';text-decoration:'+n_textDecoration+';font-weight:'+n_fontWeight+'}a.nnewsbar:hover{color:'+n_fontColorHover+';text-decoration:'+n_textDecorationHover+'}</style>');
n_p=n_pauseOnMouseOver?" onmouseover=clearTimeout(n_TIM) onmouseout=n_TIM=setTimeout('n_new()',"+n_timeOut+")>":">";
n_k=n_nS4?"":" style=text-decoration:none;color:"+n_fontColor;

function n_new(){
    if(!(n_iE||n_nSkN||n_nS4))
        return;
    var O,mes;
    O=n_iE?document.all['nnewsb']:n_nS4?document.layers['n_container'].document.layers['nnewsb']:document.getElementById('nnewsb');
    mes=n_content[n_t][0]!="" && n_cur==n_l?("<a href='"+n_content[n_t][0]+"' target='"+n_content[n_t][2]+"' class=nnewsbar"+n_p+n_content[n_t][1].substring(0,n_cur)+n_leadingSign+"</a>")"<span class=nnewsbar"+n_k+">"+n_content[n_t][1].substring(0,n_cur)+n_leadingSign+"</span>");
    if(n_nS4)
        with(O.document){
            open();
            write(mes);
            close()
        }
    else
        O.innerHTML=mes;
    if(n_cur++==n_l){
        n_cur=0;
        n_TIM=setTimeout("n_new()",n_timeOut);
        n_t++;
        if(n_t==n_content.length)
            n_t=0;n_l=n_content[n_t][1].length
    }
    else{
        setTimeout("n_new()",n_speed)
    }

}

document.write('<div '+(n_nS4?"name":"id")+'=n_container style="position:'+n_position+';top:'+n_top+'px;left:'+n_left+'px;width:'+n_width+'px;height:'+n_height+'px;clip:rect(0,'+n_width+','+n_height+',0)"><div '+(n_nS4?"name":"id")+'=nnewsb style="position:absolute;top:0px;left:0px;width:'+n_width+';height:'+n_height+'px;clip:rect(0,'+n_width+','+n_height+',0);background-color:'+n_bgColor+';layer-background-color:'+n_bgColor+';text-decoration:none;color:'+n_fontColor+'" class=nnewsbar>'+n_alternativeHTML+'</div></div>');
if(!n_nS4)
    setTimeout("n_new()",1000);
else
    window.onload=n_new;
if(n_nS4)
    onresize=function(){
        location.reload()
    }
</script>

Link to comment
Share on other sites

<script language=JavaScript1.2>
/* USE WORDWRAP AND MAXIMIZE THE WINDOW TO SEE THIS FILE
========================================
NewsBar v1.4
License : Freeware (Enjoy it!)
(c)2004 VASIL DINKOV- PLOVDIV, BULGARIA
========================================
For IE4+, NS4+, Opera7+ & Konqueror2+
========================================
Get the NewsBar script at:
http://www.smartmenus.org/other.php
and don't wait to get the Great SmartMenus script at:
http://www.smartmenus.org
LEAVE THESE NOTES PLEASE - delete the comments if you want */

// BUG in Opera:
// If you want to be able to control the body margins
// put the script right after the BODY tag, not in the HEAD!!!

// === 1 === FONT, COLORS, EXTRAS...
n_font='verdana,arial,sans-serif';
n_fontSize='11px';//10px originally
n_fontSizeNS4='12px';//11px originally
n_fontWeight='normal';
n_fontColor='#ffffff';
n_textDecoration='none';
n_fontColorHover='#ff0000';//		| won't work
n_textDecorationHover='underline';//	| in Netscape4
n_bgColor='#000000';//set [='transparent'] for transparent or use #000000
n_top=5;//100 originally	  |
n_left=20;//30 originally	  | defining
n_width=468;//500 originally      | the box
n_height=20;//14 originally       |
n_position='absolute';// absolute or relative
n_timeOut=5;//seconds
n_pauseOnMouseOver=true;
n_speed=50;//1000 = 1 second
n_leadingSign='';//originally was '_'
n_alternativeHTML='';//use www.smartmenus.org between qoutes or leave blank
// for not supported browsers like Opera<7 - usually
// you may want to put a link to your news page

// === 2 === THE CONTENT - ['href','text','target']
n_content=[
['','Welcome to the NewsBar example page!',''],
['http://www.smartmenus.org/','You can always get the latest version at: http://www.smartmenus.org/','_self'],
['http://www.smartmenus.org/','Or you may want to get the most advanced navigation system for your site?','_self']
];

// THE SERIOUS SCRIPT 
n_nS4=document.layers?1:0;
n_iE=document.all && !window.innerWidth && navigator.userAgent.indexOf("MSIE")!=-1?1:0;
n_nSkN=document.getElementById && (navigator.userAgent.indexOf("Opera")==-1 || document.body.innerHTML) && !n_iE?1:0;
n_t=0;
n_cur=0;
n_l=n_content[0][1].length;
n_timeOut*=1000;
n_fontSize2=n_nS4 && navigator.platform.toLowerCase().indexOf("win")!=-1?n_fontSizeNS4:n_fontSize;
document.write('<style>.nnewsbar,a.nnewsbar,a.nnewsbar:visited,a.nnewsbar:active{font-family:'+n_font+';font-size:'+n_fontSize2+';color:'+n_fontColor+';text-decoration:'+n_textDecoration+';font-weight:'+n_fontWeight+'}a.nnewsbar:hover{color:'+n_fontColorHover+';text-decoration:'+n_textDecorationHover+'}</style>');
n_p=n_pauseOnMouseOver?" onmouseover=clearTimeout(n_TIM) onmouseout=n_TIM=setTimeout('n_new()',"+n_timeOut+")>":">";
n_k=n_nS4?"":" style=text-decoration:none;color:"+n_fontColor;

// Modification Here
var my_count = 0;
var my_stop = 5;
// Modification End Here

function n_new(){
    // Modification Here
    if(my_count >= my_stop) {
return;
    }
    // Modification End Here

    if(!(n_iE||n_nSkN||n_nS4))
        return;
    var O,mes;
    O=n_iE?document.all['nnewsb']:n_nS4?document.layers['n_container'].document.layers['nnewsb']:document.getElementById('nnewsb');
    mes=n_content[n_t][0]!="" && n_cur==n_l?("<a href='"+n_content[n_t][0]+"' target='"+n_content[n_t][2]+"' class=nnewsbar"+n_p+n_content[n_t][1].substring(0,n_cur)+n_leadingSign+"</a>")"<span class=nnewsbar"+n_k+">"+n_content[n_t][1].substring(0,n_cur)+n_leadingSign+"</span>");
    if(n_nS4)
        with(O.document){
            open();
            write(mes);
            close()
        }
    else
        O.innerHTML=mes;
    if(n_cur++==n_l){
        n_cur=0;
        n_TIM=setTimeout("n_new()",n_timeOut);
        n_t++;

// Modification Here
        if(n_t==n_content.length) {
            n_t=0;
    my_count ++;
}
// Modification End Here

n_l=n_content[n_t][1].length;
    }
    else{
        setTimeout("n_new()",n_speed)
    }

}

document.write('<div '+(n_nS4?"name":"id")+'=n_container style="position:'+n_position+';top:'+n_top+'px;left:'+n_left+'px;width:'+n_width+'px;height:'+n_height+'px;clip:rect(0,'+n_width+','+n_height+',0)"><div '+(n_nS4?"name":"id")+'=nnewsb style="position:absolute;top:0px;left:0px;width:'+n_width+';height:'+n_height+'px;clip:rect(0,'+n_width+','+n_height+',0);background-color:'+n_bgColor+';layer-background-color:'+n_bgColor+';text-decoration:none;color:'+n_fontColor+'" class=nnewsbar>'+n_alternativeHTML+'</div></div>');
if(!n_nS4)
    setTimeout("n_new()",1000);
else
    window.onload=n_new;
if(n_nS4)
    onresize=function(){
        location.reload()
    }
</script>

 

Can try out this? Just change the my_stop variable to your desired counting loop. Eg 5, will stop the loop at 5th time.

 

Tips:

look for the modification here's comments, this indicate where I modify the code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.