Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-02-2005, 10:19 PM   PM User | #1
DavidBer
New Coder

 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
DavidBer is an unknown quantity at this point
Array - Add Delay between Elements

Hello,

I wonder if you can help me with the following question.

I am trying to display 1 phrase at a time so that a long paragraph would be easier to read. I need to insert a short delay between each element of the following array so that each phrase appears on the screen a few seconds apart from the one that came before.

For example,


Fourscore and seven years ago <--- appears first
our fathers brought forth <--- should appear 3 seconds later after the first phrase


<script type="text/javascript">
var phrase = new Array("Fourscore and seven years ago,","our fathers brought forth","on this continent","a new nation"," conceived in liberty", "and dedicated to the proposition")

for (i=0;i<phrase.length; i++)
{
(document.write(phrase[i] + " "))
}


</script>



Thank you.



David
DavidBer is offline   Reply With Quote
Old 06-02-2005, 10:37 PM   PM User | #2
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
Please try the following

PHP Code:
<HTML>
<
HEAD>
<
TITLE>Document Title</TITLE>
<
script type="text/javascript">
var 
phrase = new Array("Fourscore and seven years ago,","our fathers brought forth","on this continent","a new nation"," conceived in liberty""and dedicated to the proposition")

count=0
timer
=""
function next_phrase(){

document.getElementById("display").innerHTML+=phrase[count] + " "

count++
timer=setTimeout("next_phrase()",3000)

if(
count==phrase.length){
clearTimeout(timer)
}
}


</script>

</HEAD>
<BODY onload="next_phrase()">

<div id="display">&nbsp;</div>

</BODY>
</HTML> 
__________________
The silent one.

The most dangerous thing in the world is an idea.
The most dangerous person in the world is the one with an idea.
Mr J is offline   Reply With Quote
Old 06-02-2005, 10:39 PM   PM User | #3
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
Your question has also been answered here: http://www.webdeveloper.com/forum/sh...ad.php?t=68190
Willy Duitt is offline   Reply With Quote
Old 06-02-2005, 10:49 PM   PM User | #4
DavidBer
New Coder

 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
DavidBer is an unknown quantity at this point
Array - Add Delay between Elements - Code works

The code that Mr. J. responded with does exactly what I was asking for.

Thank you for responding so quickly.
DavidBer is offline   Reply With Quote
Old 06-03-2005, 03:40 PM   PM User | #5
DavidBer
New Coder

 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
DavidBer is an unknown quantity at this point
Array - Add Delay between Elements

Hi,

I thought you'd be interested. Ultimater on Webdeveloper.com added a replay button to the code's functionality making the routine even more useful:

<script type="text/javascript">
var phrase = new Array("Fourscore and seven years ago,","our fathers brought forth","on this continent","a new nation"," conceived in liberty", "and dedicated to the proposition")
var timerId=null
var myPhrase=0
function nextPhrase(){
clearTimeout(timerId)
document.getElementById("displayer").innerHTML+=phrase[myPhrase]+" "
myPhrase++;if(myPhrase>=phrase.length){;timerId=setTimeout("clearIt()",3000);return false}
timerId=setTimeout("nextPhrase()",3000)
}
function rePlay(){
document.getElementById("displayer").innerHTML=""
timerId=null
myPhrase=0
nextPhrase()
return true
}
function clearIt(){
clearTimeout(timerId)
document.getElementById("displayer").innerHTML="<input type=\"button\" value=\"replay\" onclick=\"rePlay()\">"
DavidBer is offline   Reply With Quote
Old 06-03-2005, 05:25 PM   PM User | #6
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
But you did not ask for a replay button

All you had to do is add this function and link to it


PHP Code:
function replay(){
count=0
document
.getElementById("display").innerHTML=""
next_phrase()

__________________
The silent one.

The most dangerous thing in the world is an idea.
The most dangerous person in the world is the one with an idea.

Last edited by Mr J; 06-03-2005 at 05:30 PM..
Mr J is offline   Reply With Quote
Old 06-03-2005, 08:02 PM   PM User | #7
DavidBer
New Coder

 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
DavidBer is an unknown quantity at this point
Smile Array - Add Delay between Elements

Thanks for the added piece of code.

True, I hadn't asked for replay, but it is helpful to have.
DavidBer is offline   Reply With Quote
Old 06-04-2005, 10:38 PM   PM User | #8
DavidBer
New Coder

 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
DavidBer is an unknown quantity at this point
How to get this routine to work as part of template

Hi,

Can anyone advise how this routine can be made generic? I would like to add it to a template file so that it could be run on any page and multiple times on a page. As it exists, the code would have to be changed each time it is run on a page.

Thanks in advance.

David
DavidBer is offline   Reply With Quote
Old 06-05-2005, 10:33 AM   PM User | #9
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,353
Thanks: 3
Thanked 456 Times in 443 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
Just Playing

PHP Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
>

<
html>

<
head>
  <
title></title>
<
script language="JavaScript" type="text/javascript">
<!--

var 
zxcContinious='Y';

var 
zxcDelay,zxcObj,zxcTxt,zxcCnt,zxcTO;
var 
zxcTxtAry=new Array();
var 
zxcReg=/<br>/g;

function 
zxcLineParse(id,nu,t){
 
zxcDelay=t;
 
zxcTxtAry=new Array();
 
zxcObj=document.getElementById(id);
 
zxcObj.onclick=function(){ if (!zxcTO){ if (!zxcCnt){ zxcCnt=0; }; zxcLineRun(); } else { clearTimeout(zxcTO); zxcTO=null; } }
 
zxcTxt=zxcObj.innerHTML;
 
zxcTxt=zxcTxt.replace(zxcReg,'<BR>');
 
zxcTxt=zxcTxt.split('<BR>');
 
zxcObj.innerHTML='';
 
zxcCnt=-1;
 for (
zxc0=0;zxc0<zxcTxt.length;zxc0++){
  if (
zxc0%nu==0){
   
zxcTTxt='';
   
zxcCnt++;
  }
  
zxcTTxt+=zxcTxt[zxc0]+'<BR>';
  
zxcTxtAry[zxcCnt]=zxcTTxt;
 }
 
zxcCnt=0;
 
zxcLineRun();
}

function 
zxcLineRun(){
 
zxcObj.innerHTML=zxcTxtAry[zxcCnt++];
 if (
zxcCnt<zxcTxtAry.length){ zxcTO=setTimeout('zxcLineRun()',zxcDelay); }
 else {
  
zxcCnt=0;
  if (
zxcContinious=='Y'){
   
zxcLineRun();
  }
 }
}

//-->
</script>
</head>

<body onload="zxcLineParse('MyLines',3,2000);" >
<p id="MyLines" >
Click Me to Start,Click Me to Stop
<br>
Line 1 Line 1 Line 1 Line 1 Line 1 Line 1 Line 1 Line 1 Line 1<br>
Line 2 Line 2 Line 2 Line 2 Line 2 Line 2 Line 2 Line 2 Line 2<br>
Line 3 Line 3 Line 3 Line 3 Line 3 Line 3 Line 3 Line 3 Line 3<br>
Line 4 Line 4 Line 4 Line 4 Line 4 Line 4 Line 4 Line 4 Line 4<br>
Line 5 Line 5 Line 5 Line 5 Line 5 Line 5 Line 5 Line 5 Line 5<br>
Line 6 Line 6 Line 6 Line 6 Line 6 Line 6 Line 6 Line 6 Line 6<br>
Line 7 Line 7 Line 7 Line 7 Line 7 Line 7 Line 7 Line 7 Line 7<br>
Line 8 Line 8 Line 8 Line 8 Line 8 Line 8 Line 8 Line 8 Line 8<br>
Line 9 Line 9 Line 9 Line 9 Line 9 Line 9 Line 9 Line 9 Line 9<br>
Line 10 Line 10 Line 10 Line 10 Line 10 Line 10 Line 10 Line 10 Line 10<br>
Line 11 Line 11 Line 11 Line 11 Line 11 Line 11 Line 11 Line 11 Line 11<br>
Line 12 Line 12 Line 12 Line 12 Line 12 Line 12 Line 12 Line 12 Line 12<br>
Line 13 Line 13 Line 13 Line 13 Line 13 Line 13 Line 13 Line 13 Line 13<br>
Line 14 Line 14 Line 14 Line 14 Line 14 Line 14 Line 14 Line 14 Line 14<br>
Line 15 Line 15 Line 15 Line 15 Line 15 Line 15 Line 15 Line 15 Line 15<br>
Line 16 Line 16 Line 16 Line 16 Line 16 Line 16 Line 16 Line 16 Line 16<br>
Line 17 Line 17 Line 17 Line 17 Line 17 Line 17 Line 17 Line 17 Line 17<br>
</p>
</body>

</html> 
Although Thing this would be better as a scroller

may be back later

Last edited by vwphillips; 06-05-2005 at 11:04 AM..
vwphillips is offline   Reply With Quote
Old 06-05-2005, 02:02 PM   PM User | #10
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,353
Thanks: 3
Thanked 456 Times in 443 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
or even

PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
>

<
html>

<
head>
  <
title></title>
<
script language="JavaScript" type="text/javascript">
<!--
// Limit Line Display lldPart1 (05-06-2005)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// Limit the number of lines displayed
// and display more lines at specified intervals.
//
// OnClick 'hold' and 'continue'.
// Optional automatic start on document load.
// There may be any number of applications on a Page.

// Application Notes and Customising Variables

// Application Notes

// The lines must be contained within an element e.g <p>
// The element must be allocated a unique id e.g. <p id="MyLines" >

// The script is initialised by a <BODY> onload event
// e.g. <body onload="lldLineDisplay('*ID*',*NumberofLines*);lldLineDisplay('MyLines2',4);" >
// where:
// *ID*    = the unique id of the element                (string)
// *NumberofLines* = the number of lines to be displayed (digit)

// the Functional Code 'lldPart2'(about 1K) is best as an extenal JavaScript

// All variables, functions etc. are prefixed with 'lld' to minimise conflicts with other JavaScripts,

// Tested with IE6 and Mozilla FoxFire

// Customising Variables

var lldDelay=1000// speed of line display (milliSeconds)
var lldStart=true// true to auto start, false for manual start

//-->
</script>

<script language="JavaScript" type="text/javascript">
<!--
// Limit Line Display lldPart2 (05-06-2005)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// Functional Code - NO Need to Change

var lldDelay,lldObj,lldTxt,lldCnt,lldTO;
var lldTxtAry=new Array();
var lldObjAry=new Array();
var lldReg=/<br>/g;

function lldLineDisplay(id,nu){
 lldObj=document.getElementById(id);
 lldObj.ary=new Array();
 lldObj.to=true;
 lldObj.onclick=function(){ if (!this.to){ this.to=true; if (!this.cnt){ this.cnt=0; } } else { this.to=false; } }
 lldTxt=lldObj.innerHTML;
 lldTxt=lldTxt.replace(lldReg,'<BR>');
 lldTxt=lldTxt.split('<BR>');
 lldCnt=-1;
 for (lld0=0;lld0<lldTxt.length;lld0++){
  if (lld0%nu==0){
   lldTTxt='';
   lldCnt++;
  }
  lldTTxt+=lldTxt[lld0]+'<BR>';
  lldObj.ary[lldCnt]=lldTTxt;
 }
 lldObj.cnt=0;
 lldObjAry[lldObjAry.length]=lldObj;
 lldObj.innerHTML=lldObj.ary[0];
 if (lldStart){
  lldLineRun();
  lldStart=false;
 }
}


function lldLineRun(){
 for (lld0=0;lld0<lldObjAry.length;lld0++){
  if (lldObjAry[lld0].to){
   lldObjAry[lld0].innerHTML=lldObjAry[lld0].ary[lldObjAry[lld0].cnt++];
   if (lldObjAry[lld0].cnt>lldObjAry[lld0].ary.length-1){
    lldObjAry[lld0].cnt=0;
   }
  }
 }
 lldTO=setTimeout('lldLineRun()',lldDelay);
}

//-->
</script>
</head>

<body onload="lldLineDisplay('MyLines',3,2000);lldLineDisplay('MyLines2',4);" >
<p id="MyLines"  style="height:100px;" >
Click Me to Start,Click Me to Stop
<br>
Line 1 Line 1 Line 1 Line 1 Line 1 Line 1 Line 1 Line 1 Line 1<br>
Line 2 Line 2 Line 2 Line 2 Line 2 Line 2 Line 2 Line 2 Line 2<br>
Line 3 Line 3 Line 3 Line 3 Line 3 Line 3 Line 3 Line 3 Line 3<br>
Line 4 Line 4 Line 4 Line 4 Line 4 Line 4 Line 4 Line 4 Line 4<br>
Line 5 Line 5 Line 5 Line 5 Line 5 Line 5 Line 5 Line 5 Line 5<br>
Line 6 Line 6 Line 6 Line 6 Line 6 Line 6 Line 6 Line 6 Line 6<br>
Line 7 Line 7 Line 7 Line 7 Line 7 Line 7 Line 7 Line 7 Line 7<br>
Line 8 Line 8 Line 8 Line 8 Line 8 Line 8 Line 8 Line 8 Line 8<br>
Line 9 Line 9 Line 9 Line 9 Line 9 Line 9 Line 9 Line 9 Line 9<br>
Line 10 Line 10 Line 10 Line 10 Line 10 Line 10 Line 10 Line 10 Line 10<br>
Line 11 Line 11 Line 11 Line 11 Line 11 Line 11 Line 11 Line 11 Line 11<br>
Line 12 Line 12 Line 12 Line 12 Line 12 Line 12 Line 12 Line 12 Line 12<br>
Line 13 Line 13 Line 13 Line 13 Line 13 Line 13 Line 13 Line 13 Line 13<br>
Line 14 Line 14 Line 14 Line 14 Line 14 Line 14 Line 14 Line 14 Line 14<br>
Line 15 Line 15 Line 15 Line 15 Line 15 Line 15 Line 15 Line 15 Line 15<br>
Line 16 Line 16 Line 16 Line 16 Line 16 Line 16 Line 16 Line 16 Line 16<br>
Line 17 Line 17 Line 17 Line 17 Line 17 Line 17 Line 17 Line 17 Line 17<br>
</p>
<p id="MyLines2"  style="height:100px;" >
Click Me to Start,Click Me to Stop
<br>
Line 1 Line 1 Line 1 Line 1 Line 1 Line 1 Line 1 Line 1 Line 1<br>
Line 2 Line 2 Line 2 Line 2 Line 2 Line 2 Line 2 Line 2 Line 2<br>
Line 3 Line 3 Line 3 Line 3 Line 3 Line 3 Line 3 Line 3 Line 3<br>
Line 4 Line 4 Line 4 Line 4 Line 4 Line 4 Line 4 Line 4 Line 4<br>
Line 5 Line 5 Line 5 Line 5 Line 5 Line 5 Line 5 Line 5 Line 5<br>
Line 6 Line 6 Line 6 Line 6 Line 6 Line 6 Line 6 Line 6 Line 6<br>
Line 7 Line 7 Line 7 Line 7 Line 7 Line 7 Line 7 Line 7 Line 7<br>
Line 8 Line 8 Line 8 Line 8 Line 8 Line 8 Line 8 Line 8 Line 8<br>
Line 9 Line 9 Line 9 Line 9 Line 9 Line 9 Line 9 Line 9 Line 9<br>
Line 10 Line 10 Line 10 Line 10 Line 10 Line 10 Line 10 Line 10 Line 10<br>
Line 11 Line 11 Line 11 Line 11 Line 11 Line 11 Line 11 Line 11 Line 11<br>
Line 12 Line 12 Line 12 Line 12 Line 12 Line 12 Line 12 Line 12 Line 12<br>
Line 13 Line 13 Line 13 Line 13 Line 13 Line 13 Line 13 Line 13 Line 13<br>
Line 14 Line 14 Line 14 Line 14 Line 14 Line 14 Line 14 Line 14 Line 14<br>
Line 15 Line 15 Line 15 Line 15 Line 15 Line 15 Line 15 Line 15 Line 15<br>
Line 16 Line 16 Line 16 Line 16 Line 16 Line 16 Line 16 Line 16 Line 16<br>
Line 17 Line 17 Line 17 Line 17 Line 17 Line 17 Line 17 Line 17 Line 17<br>
</p>
</body>

</html> 

Last edited by vwphillips; 06-05-2005 at 02:55 PM..
vwphillips is offline   Reply With Quote
Old 06-05-2005, 09:20 PM   PM User | #11
DavidBer
New Coder

 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
DavidBer is an unknown quantity at this point
Array - Add Delay between Elements

Thank you for taking the time to present a different solution. I like the abilty to start and stop with a mouse click. But let me describe in a little more detail what I am trying to do:

In order to read large amounts of text on the screen easily, I want to present meaning parts of a sentence on the screen. One part appears and then after a short delay, a second part appears and then after a short delay the third part appears until the whole sentence appears on the screen. The process continues until the whole paragraph is on the screen. Then the second paragraph is displayed in the same way as the first until the entire page is displayed.

Your solution displays entire sentences (lines) not parts, and then washes them away. If the parts could be joined together as described above and kept on the screen, then it looks like I'd have the generic routine I am looking for.

Thanks again for taking the time.
DavidBer is offline   Reply With Quote
Old 06-05-2005, 11:06 PM   PM User | #12
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
This is still in the editing stage but give it a try to see if its on the right lines


PHP Code:
<HTML
<
HEAD
<
TITLE>Document Title</TITLE
<
script type="text/javascript">
<!--

var 
message_obj1=new message_reader('display',1000)
message_obj1_array=new Array("Fourscore and seven years ago","our fathers brought forth","on this continent","a new nation"," conceived in liberty","and dedicated to the proposition")

var 
message_obj2=new message_reader('display2',2000)
message_obj2_array=new Array("Seperate messages","can be shown","in the same page","with individual speed","control")

var 
message_obj3=new message_reader('display3',3000)
message_obj3_array=new Array("I suppose you could have","any number of displays","in the same page","simply by creating a","new object for it to be shown")


function 
message_reader(id,speed){
var 
count=
var timer=null
var running=0

this
.next_message=function(n){
running=1
//document.getElementById(id).innerHTML="" 
document.getElementById(id).innerHTML+=window[n+"_array"][count] + " " 
count++ 
timer setTimeout(n+".next_message('"+n+"')",speed)

if(
count==window[n+"_array"].length){ 
clearTimeout(timer)
count=0
running
=0



this.replay_message_message=function(n){
if(
running==1){return}
clearTimeout(timer
count=
document
.getElementById(id).innerHTML="" 
timer setTimeout(n+".next_message('"+n+"')",speed)


this.stop_message = function(){
if(
timer){
clearTimeout(timer)
running=0
}
}

}

function 
init(){
message_obj1.next_message('message_obj1')
message_obj2.next_message('message_obj2')
message_obj3.next_message('message_obj3')
}
//-->
</script> 

</HEAD> 
<BODY onload="init()"> 

<div id="display">&nbsp;</div> 
<BR><BR>

<div id="display2">&nbsp;</div> 

<BR><BR>

<div id="display3">&nbsp;</div> 

</BODY> 
</HTML> 
Or do you mean something like this?

PHP Code:
<HTML>
<
HEAD
<
TITLE>Document Title</TITLE>  
<
script type="text/javascript"
<!-- 

paragraph1=new Array("Fourscore and seven years ago","our fathers brought forth","on this continent","a new nation"," conceived in liberty","and dedicated to the proposition"

paragraph2=new Array("Seperate messages","can be shown","in the same page","with individual speed","control"

paragraph3=new Array("I suppose you could have","any number of displays","in the same page","simply by creating a","new object for it to be shown"

num=1
index
=0
timer
=null 
speed
=1000
paras
=3

function init(){
document.getElementById("display"+num).innerHTML=""
message_reader2()
}


function 
message_reader2(){
document.getElementById("display"+num).innerHTML+=window["paragraph"+num][index] + " "  
index++  
timer setTimeout("message_reader2()",speed


if(
index==window["paragraph"+num].length){  
clearTimeout(timer
index=
if(num!=paras){
num++
setTimeout("init()",3000)
}
}

}  
 
//--> 
</script>  

</HEAD> 
<BODY onload="init()"> 

<div id="display1">&nbsp;</div> 
<BR><BR> 

<div id="display2">&nbsp;</div> 

<BR><BR> 

<div id="display3">&nbsp;</div> 

</BODY> 
</HTML> 
__________________
The silent one.

The most dangerous thing in the world is an idea.
The most dangerous person in the world is the one with an idea.

Last edited by Mr J; 06-05-2005 at 11:31 PM..
Mr J is offline   Reply With Quote
Old 06-06-2005, 04:37 AM   PM User | #13
DavidBer
New Coder

 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
DavidBer is an unknown quantity at this point
Array - Add Delay between Elements

Mr J.

Thank you again for taking the time. It is important for me to get this routine to work and I appreciate your suggestions.

Your second example comes very close to what I am trying to do. The "paragraphs" are displayed in the manner I am seeking. However, I need to have other paragraphs be displayed in the same way elsewhere on the page at different times.

I suspect that if I could get control of the "num" value and assign it to the paragraph and the display object, then I would have control over when and where the paragraph is displayed.

I changed the line "function message_reader2()" to "function message_reader2(num)" and then called the function as follows:

<p onClick="javascript:message_reader2(1) ;">Click to display message</p>

However, only the first phrase appeared on the screen.

Obviously, there is something I am not understanding. Any suggestions ??

Thank you.

David
DavidBer is offline   Reply With Quote
Old 06-06-2005, 08:12 AM   PM User | #14
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,353
Thanks: 3
Thanked 456 Times in 443 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
Done?

but will need to get the page to scroll for the text to remain in view


PHP Code:
<SCRIPT language=JavaScript type=text/javascript>
<!--
// Limit Line Display lldPart1 (05-06-2005)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// Limit the number of lines displayed
// and display more lines at specified intervals.
//
// OnClick 'hold' and 'continue'.
// Optional automatic start on document load.
// There may be any number of applications on a Page.

// Application Notes and Customising Variables

// Application Notes

// The lines must be contained within an element e.g <p>
// The element must be allocated a unique id e.g. <p id="MyLines" >

// The script is initialised by a <BODY> onload event
// e.g. <body onload="lldLineDisplay('*ID*',*NumberofLines*);lldLineDisplay('MyLines2',4);" >
// where:
// *ID*    = the unique id of the element                (string)
// *NumberofLines* = the number of lines to be displayed (digit)

// the Functional Code 'lldPart2'(about 1K) is best as an extenal JavaScript

// All variables, functions etc. are prefixed with 'lld' to minimise conflicts with other JavaScripts,

// Tested with IE6 and Mozilla FoxFire

// Customising Variables

var lldDelay=1000// speed of line display (milliSeconds)
var lldStart=true// true to auto start, false for manual start

//-->
</SCRIPT>

<SCRIPT language=JavaScript type=text/javascript>
<!--
// Limit Line Display lldPart2 (05-06-2005)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// Functional Code - NO Need to Change

var lldDelay,lldObj,lldTxt,lldCnt,lldTO;
var lldTxtAry=new Array();
var lldObjAry=new Array();
var lldReg=/<br>/g;

function lldLineDisplay(id,nu){
 lldObj=document.getElementById(id);
 lldObj.ary=new Array();
 lldObj.to=true;
 lldObj.txt='';
 lldObj.onclick=function(){ if (!this.to){ this.to=true; if (!this.cnt){ this.cnt=0; } } else { this.to=false; } }
 lldTxt=lldObj.innerHTML;
 lldTxt=lldTxt.replace(lldReg,'<BR>');
 lldTxt=lldTxt.split('<BR>');
 lldCnt=-1;
 for (lld0=0;lld0<lldTxt.length;lld0++){
  if (lld0%nu==0){
   lldTTxt='';
   lldCnt++;
  }
  lldTTxt+=lldTxt[lld0]+'<BR>';
  lldObj.ary[lldCnt]=lldTTxt;
 }
 lldObj.cnt=0;
 lldObjAry[lldObjAry.length]=lldObj;
 lldObj.innerHTML=lldObj.ary[0];
 if (lldStart){
  lldLineRun();
  lldStart=false;
 }
}


function lldLineRun(){
 for (lld0=0;lld0<lldObjAry.length;lld0++){
  if (lldObjAry[lld0].to){
   lldObjAry[lld0].txt+=lldObjAry[lld0].ary[lldObjAry[lld0].cnt++];
  lldObjAry[lld0].innerHTML=lldObjAry[lld0].txt
   if (lldObjAry[lld0].cnt>lldObjAry[lld0].ary.length-1){
   lldObjAry[lld0].to=false; // ----------------------------- Optional
   lldObjAry[lld0].cnt=0;
    lldObjAry[lld0].txt='';
   }
  }
 }
 lldTO=setTimeout('lldLineRun()',lldDelay);
}

//-->
</SCRIPT> 

Last edited by vwphillips; 06-06-2005 at 08:18 AM..
vwphillips is offline   Reply With Quote
Old 06-06-2005, 02:28 PM   PM User | #15
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
Ok, give this a try

PHP Code:
<HTML>
<
HEAD
<
TITLE>Document Title</TITLE>  
<
script type="text/javascript"
<!-- 

paragraph1=new Array("Fourscore and seven years ago","our fathers brought forth","on this continent","a new nation"," conceived in liberty","and dedicated to the proposition"

paragraph2=new Array("Lorem ipsum dolor sit amet, ","consectetuer adipiscing elit. ","Suspendisse tincidunt. ","Pellentesque semper lacus ut mauris. ","vestibulum ante ipsum primis in ","faucibus orci luctus et ultrices posuere cubilia curae ","Maecenas malesuada arcu et tortor. Aliquam ligula elit "

paragraph3=new Array("Lorem ipsum ","sed cursus mattis lorem ","donec egestas ipsum ac nisl ","duis sollicitudin, mi ac rutrum ornare ","tortor magna volutpat leo ","vel tristique tellus lorem quis diam."

index=0
running
=0
timer
=null 
speed
=1000

function message_reader(num){
if(
running==1){
return
}
document.getElementById("display"+num).innerHTML=""
run_reader(num)
}

function 
run_reader(num){
running=1
document
.getElementById("display"+num).innerHTML+=window["paragraph"+num][index] + " "  
index++  
timer setTimeout("run_reader("+num+")",speed

if(
index==window["paragraph"+num].length){  
clearTimeout(timer
index=0
running
=0
document
.getElementById("d"+num).innerHTML="Replay message "+num
}



//--> 
</script>  

</HEAD> 
<BODY>

<div id="d1" onclick="message_reader(1)" style="cursor:hand;cursor:pointer;font-weight:bold">Click to display message 1</div>
<div id="display1">&nbsp;</div> 

<BR><BR> 

<div id="d2" onclick="message_reader(2)" style="cursor:hand;cursor:pointer;font-weight:bold">Click to display message 2</div>
<div id="display2">&nbsp;</div> 

<BR><BR> 

<div id="d3" onclick="message_reader(3)" style="cursor:hand;cursor:pointer;font-weight:bold">Click to display message 3</div>
<div id="display3">&nbsp;</div> 

</BODY> 
</HTML> 
__________________
The silent one.

The most dangerous thing in the world is an idea.
The most dangerous person in the world is the one with an idea.
Mr J is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:12 PM.


Advertisement
Log in to turn off these ads.