Visualizzazione dei risultati da 1 a 10 su 10
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2000
    Messaggi
    223

    testo scorrevole da file .txt o .xml si puo' ?

    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 ?

  2. #2

    ..........

    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

  3. #3

    Re: ..........

    Originariamente inviato da whisher
    ... per il testo scorrevole non saprei ma con solo js non si può ...
    .... 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)
    codice:
    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"))};
    al fine di far apparire il testo dal basso e farlo sparire in alto
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  4. #4

    ........

    per il testo scorrevole non saprei ma con solo js non si può
    mi riferivo a:
    un testo scorrevole preso da un file .txt o eventualmente .xml


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2000
    Messaggi
    223
    grazie ad entrambi troppo gentili

  6. #6
    Utente di HTML.it
    Registrato dal
    Jul 2000
    Messaggi
    223

    Re: Re: ..........

    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)
    codice:
    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"))};
    al fine di far apparire il testo dal basso e farlo sparire in alto
    ecco ma solo una domanda l'include del file .txt (o xml) dove lo faccio ?

  7. #7

    Re: Re: Re: ..........

    Originariamente inviato da franco112
    ecco ma solo una domanda l'include del file .txt (o xml) dove lo faccio ?
    dove ti pare con un linguaggio server, sfruttando ajax se non puoi farne a meno

    <div id="tsco"><?php echo file_get_contents('testo.txt'); ?></div>
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  8. #8

    Re: ..........

    Originariamente inviato da whisher Questo è un ticker qui
    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.

    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:
    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>
    Spero in un vostro aiuto. Grazie anticipatamente!

  9. #9
    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
    Codice PHP:
    header('Content-type: text/html; charset=utf-8'); 
    prima dell'echo.

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  10. #10
    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

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.