February 16, 201115 yr Hi, I am new to javascript and want to be able to delay the scrolling numbers part of the below script to start after the fade in function. I've tried tinkering and searching on google but cannot find what i am looking for, maybe due to a lack of knowledge of javascript terminology. Thanks for your help <p id="me" style="zoom: 1;"> Our current win rate is. </p> <script type="text/javascript"> var element = document.getElementById('me'); var duration = 8000; /* 1000 millisecond fade = 1 sec */ var steps = 200; /* number of opacity intervals */ /* set the opacity of the element (between 0.0 and 1.0) */ function setOpacity(level) { element.style.opacity = level; element.style.MozOpacity = level; element.style.KhtmlOpacity = level; element.style.filter = "alpha(opacity=" + (level * 100) + ");"; } function fadeIn(){ for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + i + ")", i * duration); } setTimeout("fadeOut()", delay); } function fadeOut() { for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + (1 - i) + ")", i * duration); } setTimeout("fadeIn()", duration); } /* start the effect */ fadeIn(); </script> <script type="text/javascript"> var text="86"; document.write("<big><tt id=dis nowrap>Display Area</tt></big>"); var symtype=new Array(" ","1","2","3","4","5","6","7","8","9","10","F","f","G","g","H","h","I","i","J","j","K","k","L","l","M","m","N","n","O","o","P","p","Q","q","R","r","S","s","T","t","U","u","V","v","W","w","X","x","Y","y","Z","z","0","1","2","3","4","5","6","7","8","9","%",",","&","!","?","-","_"); var symarray=new Array(); for (var i=0; i<text.length; i++){ symarray[i]=" ";} function scroll(){ for (var i=0; i<text.length; i++){ if (symarray[i]!=text.substring(i,i+1)) { for (var x=0; x<70; x++) if (symarray[i]==symtype[x]) {symarray[i]=symtype[x+1]; break}} }var outsym=""; for (var i=0; i<text.length; i++) outsym+=symarray[i]; dis.innerHTML=outsym; setTimeout('scroll()',100); }scroll(); </script>
February 16, 201115 yr At the end of your code, change it to: dis.innerHTML=outsym; setTimeout('scroll()',100); } setTimeout('scroll()',2000); And also delete "Display Area" from this line: document.write("<big><tt id=dis nowrap>Display Area</tt></big>"); Otherwise it will say "Display Area" until the function runs.
February 16, 201115 yr Author At the end of your code, change it to: dis.innerHTML=outsym; setTimeout('scroll()',100); } setTimeout('scroll()',2000); And also delete "Display Area" from this line: document.write("<big><tt id=dis nowrap>Display Area</tt></big>"); Otherwise it will say "Display Area" until the function runs. Splendid, thank you my friend.
February 16, 201115 yr Author Sorry to ask again but I have added another function that I want to start last, it's the last script on the below example. Currently the "%" starts fadiing straight away, when it should be happening last, and prevents the first fade script from functioning. What am i doing wrong? Thanks again. <div id="wrapper"> <p id="me"> Our success rate in work winning is </p> <script type="text/javascript"> var element = document.getElementById('me'); var duration = 8000; /* 1000 millisecond fade = 1 sec */ var steps = 200; /* number of opacity intervals */ /* set the opacity of the element (between 0.0 and 1.0) */ function setOpacity(level) { element.style.opacity = level; element.style.MozOpacity = level; element.style.KhtmlOpacity = level; element.style.filter = "alpha(opacity=" + (level * 100) + ");"; } function fadeIn(){ for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + i + ")", i * duration); } setTimeout("fadeOut()", delay); } function fadeOut() { for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + (1 - i) + ")", i * duration); } setTimeout("fadeIn()", duration); } /* start the effect */ fadeIn(); </script> <div id="content"> <div id="winrate"> <script type="text/javascript"> var text="86"; document.write("<big><tt id=dis nowrap></tt></big>"); var symtype=new Array(" ","1","2","3","4","5","6","7","8","9","10","F","f","G","g","H","h","I","i","J","j","K","k","L","l","M","m","N","n","O","o","P","p","Q","q","R","r","S","s","T","t","U","u","V","v","W","w","X","x","Y","y","Z","z","0","1","2","3","4","5","6","7","8","9","%",",","&","!","?","-","_"); var symarray=new Array(); for (var i=0; i<text.length; i++){ symarray[i]=" ";} function scroll(){ for (var i=0; i<text.length; i++){ if (symarray[i]!=text.substring(i,i+1)) { for (var x=0; x<70; x++) if (symarray[i]==symtype[x]) {symarray[i]=symtype[x+1]; break}} }var outsym=""; for (var i=0; i<text.length; i++) outsym+=symarray[i]; dis.innerHTML=outsym; setTimeout('scroll()',100); } setTimeout('scroll()',8000); </script> </div> <div id="percent"> <div id="percentsign"> % </div> <script type="text/javascript"> var element = document.getElementById('percentsign'); var duration = 2000; /* 1000 millisecond fade = 1 sec */ var steps = 200; /* number of opacity intervals */ /* set the opacity of the element (between 0.0 and 1.0) */ function setOpacity(level) { element.style.opacity = level; element.style.MozOpacity = level; element.style.KhtmlOpacity = level; element.style.filter = "alpha(opacity=" + (level * 100) + ");"; } function fadeIn(){ for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + i + ")", i * duration); } setTimeout("fadeOut()", delay); } function fadeOut() { for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + (1 - i) + ")", i * duration); } setTimeout("fadeIn()", duration); } /* start the effect */ setTimeout('fadeIn()',9000); </script> </div> </div> </div>
Create an account or sign in to comment