per caso qualcuno saprebbe dirmi se sia possibile inserire (con un javascript) un testo scorrevole preso da un file .txt o eventualmente .xml in una pagina .html ?
![]()
per caso qualcuno saprebbe dirmi se sia possibile inserire (con un javascript) un testo scorrevole preso da un file .txt o eventualmente .xml in una pagina .html ?
![]()
Ciao.
Questo è un ticker qui
lo puoi fare con Ajax per il testo scorrevole non saprei ma con solo
js non si può.
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
.... solo con js senza ticker ne Ajax ...Originariamente inviato da whisher
... per il testo scorrevole non saprei ma con solo js non si può ...
codice:<script type="text/javascript"> onload = function() { var div = document.getElementById("tsco"); setInterval(function(){ if(div.lastScroll === div.scrollTop) div.scrollTop = -1; div.lastScroll = div.scrollTop++; }, 100); } </script> <style type="text/css"> #tsco { width: 200px; height: 80px; border: 1px solid silver; padding: 2px; margin: 20px; font-family: Verdana, Helvetica, sans-serif; font-size: 8pt; overflow: hidden; } </style> <div id="tsco"> j caiojoiwiwaoaiaejieacijea jaeio j aoieicej aojiaiajoi cjecj ioajc cjaio coi ecioaiojcoejac ajic eajoieacjeja aj ecjocj oajecoijc aj aci jeacoijacjcjoiaej coij coia joijc ajci jaeocijacjjciacajecieajoiea joieaoij ioa coaje j aoicacoiaecioajcioajc oiajcoicj oia eoicioaj c aj icj aiocioac ioajcoiacjoiajc oijc oiaj oijcoi jcaocj jaic joia jcoieaj coi ejajc </div>
[edit]
in alternativa per una cosa più "simaptica" si potrebbe fare così (tutto uguale a prima tranne il codice JS da sostituire con questo)
al fine di far apparire il testo dal basso e farlo sparire in altocodice:function fakeMarque(div){ var text = div.innerHTML; div.innerHTML = ""; while(!div.scrollTop) div.innerHTML = div.innerHTML.concat(++div.scrollTop, " "); div.scrollTop = 0; div.innerHTML = div.innerHTML.replace(/[0-9]+/g, ""); div.innerHTML = div.innerHTML.concat(text, div.innerHTML); setInterval(function(){ if(div.lastScroll === div.scrollTop) div.scrollTop = -1; div.lastScroll = div.scrollTop++; }, 100); }; onload = function(){fakeMarque(document.getElementById("tsco"))};
mi riferivo a:per il testo scorrevole non saprei ma con solo js non si può
un testo scorrevole preso da un file .txt o eventualmente .xml
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
grazie ad entrambi troppo gentili
ecco ma solo una domanda l'include del file .txt (o xml) dove lo faccio ?Originariamente inviato da andr3a
.... solo con js senza ticker ne Ajax ...
codice:<script type="text/javascript"> onload = function() { var div = document.getElementById("tsco"); setInterval(function(){ if(div.lastScroll === div.scrollTop) div.scrollTop = -1; div.lastScroll = div.scrollTop++; }, 100); } </script> <style type="text/css"> #tsco { width: 200px; height: 80px; border: 1px solid silver; padding: 2px; margin: 20px; font-family: Verdana, Helvetica, sans-serif; font-size: 8pt; overflow: hidden; } </style> <div id="tsco"> j caiojoiwiwaoaiaejieacijea jaeio j aoieicej aojiaiajoi cjecj ioajc cjaio coi ecioaiojcoejac ajic eajoieacjeja aj ecjocj oajecoijc aj aci jeacoijacjcjoiaej coij coia joijc ajci jaeocijacjjciacajecieajoiea joieaoij ioa coaje j aoicacoiaecioajcioajc oiajcoicj oia eoicioaj c aj icj aiocioac ioajcoiacjoiajc oijc oiaj oijcoi jcaocj jaic joia jcoieaj coi ejajc </div>
[edit]
in alternativa per una cosa più "simaptica" si potrebbe fare così (tutto uguale a prima tranne il codice JS da sostituire con questo)
al fine di far apparire il testo dal basso e farlo sparire in altocodice:function fakeMarque(div){ var text = div.innerHTML; div.innerHTML = ""; while(!div.scrollTop) div.innerHTML = div.innerHTML.concat(++div.scrollTop, " "); div.scrollTop = 0; div.innerHTML = div.innerHTML.replace(/[0-9]+/g, ""); div.innerHTML = div.innerHTML.concat(text, div.innerHTML); setInterval(function(){ if(div.lastScroll === div.scrollTop) div.scrollTop = -1; div.lastScroll = div.scrollTop++; }, 100); }; onload = function(){fakeMarque(document.getElementById("tsco"))};
dove ti pare con un linguaggio server, sfruttando ajax se non puoi farne a menoOriginariamente inviato da franco112
ecco ma solo una domanda l'include del file .txt (o xml) dove lo faccio ?
<div id="tsco"><?php echo file_get_contents('testo.txt'); ?></div>
Ciao whisher... scusate se riporto in alto questo post... ma stavo cercando un ticker in ajax come quello che hai segnalato nel link sopra e dopo aver prelaevato l'esempio mi ritrovo a doverlo modificare per adattarlo al mio scopo.Originariamente inviato da whisher Questo è un ticker qui
Il problema sostanzialmente è che l'esempio lavora con un file di testo che contiene le news, mentre le mie news sono memorizzate in un DataBase mysql... ora, da ignorante, mi/vi chiedo se è possibile e se ne vale la pena, modificare l'esempio per farlo funzionare con una query al DB invece del file di testo!
Vi posto il codice della pagina:
Spero in un vostro aiuto. Grazie anticipatamente!codice:<script language="JavaScript" type="text/javascript"> var i = 0; var time = 2000;//Time tra una news e l'altra var page = "technews.txt";//File delle news formato news uno | news due | etc //Gets the browser specific XmlHttpRequest Object function getXmlHttpRequestObject() { var receiveReq=false; //Clear our fetching variable try { receiveReq = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object… } catch (e) { try { receiveReq = new ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object } catch (e) { receiveReq = false; } } if (!receiveReq && typeof XMLHttpRequest!='undefined') { receiveReq = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest } return receiveReq; } //Get our browser specific XmlHttpRequest object. var receiveReq = getXmlHttpRequestObject(); //Initiate the asyncronous request. function getNews() { //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call. if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { //Setup the connection as a GET call to your page //True explicity sets the request to asyncronous (default). receiveReq.open('GET', page , true); //Set the function that will be called when the XmlHttpRequest objects state changes. receiveReq.onreadystatechange = handlegetNews; //Make the actual request. receiveReq.send(null); } } //Called every time our XmlHttpRequest objects state changes. function handlegetNews() { //Check to see if the XmlHttpRequests state is finished. if (receiveReq.readyState == 4) { //Set the contents of our span element to the result of the asyncronous call. var content = receiveReq.responseText; var arraycontent = content.split('|'); if(i==arraycontent.length) { i=0; } document.getElementById('news').innerHTML = arraycontent[i]; setTimeout('handlegetNews()',time); i++; } } window.onload = function() { getNews(); } </script> </head> <body> <p id="news"></p> </body> </html>![]()
Ciao.
Non fai altro che o scrivere le
news che recuperi dal Db in un file di testo
(divise da |).
Oppure fare un echo del risultato sempre diviso
da | in questo caso il file technews.txt sarà
technews.php
in questo caso usa
prima dell'echo.Codice PHP:
header('Content-type: text/html; charset=utf-8');
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Grazie per la risposta... senti, ho da chiederti due piccole info:
1) Mi spieghi il perchè di header('Content-type: text/html; charset=utf-8'); ??
2) Se volessi recuperare due campi dal DB, tipo la data e il testo e metterli su due righe, come potrei fare? ...cioè, nel file php riesco a farlo, ma poi come faccio a formattare l'output finale a mio piacimento? tipo la data in rosso e il testo in nero?
Devo formattare con i vari tag, tutto direttamente nel file technews.php o va fatto diversamente?
Grazie ancora!
Ciao