CiberSkull Posted November 23, 2009 at 04:48 PM Report Share #297295 Posted November 23, 2009 at 04:48 PM Hi, Da ultima vez que aqui estive, não sabia como como ir buscar o texto de uns elementos. Agora, sim porque as duvidas nunca acabam, quero por o que retirei noutro sitio. A ideia geral é fazer um Type Writer. No FF e Chrome funciona bem, no IE apenas escreve Undefined... o código: Deve escrever aqui: <div class="div_typescroller" id="div_typescroller"> </div> Vai buscar o Conteúdo aqui: <div id="typescroller_content" style="display:none;"> <P>Heeeeellllllllllloooooooo</P> <P>I'm ALIVE!</P> </div O Codigo que poe e vai buscar é este: <script type="text/javascript"> var arr = new Array(); var lines; var line = new Array(); var cursor = "-"; var temp = new Array(); var curr_line=0; var curr_char = 0; function next(){ if (cursor=="\\"){ cursor="|"} else if (cursor=="|"){ cursor="/"} else if (cursor=="/"){ cursor="-"} else if (cursor=="-"){ cursor="\\"} if(temp==line[curr_line]) { temp=""; if(++curr_line==lines) curr_line=0; curr_char=0; setTimeout("animate()", 1000); } else { curr_char++; setTimeout("animate()", 100); } } function animate(){ temp+=""+line[curr_line][curr_char]; $("#div_typescroller").html(temp + cursor); next(); }; $(document).ready(function(){ var htmlstr; $('#typescroller_content P').each(function (i) { arr[i] = $(this).text(); }); var newhtml; var i ; var k = arr.length; var j = 0; for(i = 0 ; i<k;i++) { // alert(j); if(arr[i].toString() !=" " && arr[i].toString().length >0) line[j++]=arr[i]; } lines=j; animate(); }); </script> Em vez de usar uma div também tentei usar: <form name="typescroller"> <input border="0" type="text" id="div_typescroller" size="30"> </form> adaptando o código: <script type="text/javascript"> var arr = new Array(); var lines; var line = new Array(); var cursor = "-"; var temp = new Array(); var curr_line=0; var curr_char = 0; function next(){ if (cursor=="\\"){ cursor="|"} else if (cursor=="|"){ cursor="/"} else if (cursor=="/"){ cursor="-"} else if (cursor=="-"){ cursor="\\"} if(temp==line[curr_line]) { temp=""; if(++curr_line==lines) curr_line=0; curr_char=0; setTimeout("animate()", 1000); } else { curr_char++; setTimeout("animate()", 100); } } function animate(){ temp+=""+line[curr_line][curr_char]; $("#div_typescroller").val(temp + cursor); next(); }; $(document).ready(function(){ var htmlstr; $('#typescroller_content P').each(function (i) { arr[i] = $(this).text(); }); var newhtml; var i ; var k = arr.length; var j = 0; for(i = 0 ; i<k;i++) { // alert(j); if(arr[i].toString() !=" " && arr[i].toString().length >0) line[j++]=arr[i]; } lines=j; animate(); }); </script> caso tenha que usar o input como é ponho a parecer invisivel (a border)? Agradeço desde já a vossa ajuda Link to comment Share on other sites More sharing options...
yoda Posted November 23, 2009 at 06:21 PM Report Share #297308 Posted November 23, 2009 at 06:21 PM border: none; ou border da cor do background. before you post, what have you tried? - http://filipematias.info sense, purpose, direction Link to comment Share on other sites More sharing options...
CiberSkull Posted November 23, 2009 at 06:22 PM Author Report Share #297310 Posted November 23, 2009 at 06:22 PM e em relação ao bug? thanks for the answer Link to comment Share on other sites More sharing options...
yoda Posted November 23, 2009 at 06:24 PM Report Share #297311 Posted November 23, 2009 at 06:24 PM O bug não sei. O link que puseste nao funciona e não faço ideia do que queres fazer. before you post, what have you tried? - http://filipematias.info sense, purpose, direction Link to comment Share on other sites More sharing options...
CiberSkull Posted November 23, 2009 at 06:40 PM Author Report Share #297315 Posted November 23, 2009 at 06:40 PM parece estar down..- aqui vai outro: http://javascripts.vbarsan.com/ é o Typewriter Vertical Scroller estive a tenta usar o debbuger do ie e esta tudo em as variaveis estao bem, os indices tambem. mas qdo faz: temp+=""+line[curr_line][curr_char]; temp fica com "undefined" não percebo... Link to comment Share on other sites More sharing options...
CiberSkull Posted November 24, 2009 at 11:13 AM Author Report Share #297390 Posted November 24, 2009 at 11:13 AM hey, Já descobri o erro. Estava a tratar a string como faria em C/C++/D devia ser: temp+=""+line[curr_line].charAt(curr_char); Estranho o FF e chrome assumirem como correcto e o IE não.. Obrigado e tudo de bom. Miguel Rossi Seabra Link to comment Share on other sites More sharing options...
cyclop Posted November 30, 2009 at 09:58 AM Report Share #298052 Posted November 30, 2009 at 09:58 AM Tem atenção quando colocas "Jquery" no tópico quando deveria ser "o meu javascript". Acho que deverias rever um pouco a lógica de programação que fazes, estou a ver algumas coisas que poderias fazer usando a framework jquery e estás a usar os métodos do engine do javascript "Quando eu for grande quero ser como o Celso" Link to comment Share on other sites More sharing options...
CiberSkull Posted November 30, 2009 at 10:48 AM Author Report Share #298059 Posted November 30, 2009 at 10:48 AM Como por exemplo? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now