Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    22

    funzione simile a sleep

    Ciao volevo sapere se esiste una funzione simile a sleep() che non blocchi tutto il sito ma solo uno script
    grazie

  2. #2
    Dove si trova lo script? Viene richiamato da un'altra pagina?
    Sleep ferma tutto. Dovresti riuscire ad adattarlo oppure di usare js.
    Eccoti un link che ti spiega e da suggerimenti oltre ad esempi.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    22
    Grazie per la risposta ho visto un po come funziona e andrebbe bene, però ho visto nell'esempio stop the timer che vorrei utilizare io
    Codice PHP:
    <!DOCTYPE html>
    <
    html>
    <
    body>



    Click the first button to display the current time, and the second button to stop the time.</p>
    <
    button onclick="myFunction()">Try it</button>
    <
    button onclick="myStopFunction()">Stop time</button>

    <
    script>
    var 
    myVar;

    function 
    myFunction()
    {
    myVar=setInterval(function(){myTimer()},1000);
    }

    function 
    myTimer()
    {
    var 
    d=new Date();
    var 
    t=d.toLocaleTimeString();
    document.getElementById("demo").innerHTML=t;
    }

    function 
    myStopFunction()
    {
    clearInterval(myVar);
    }
    </script>

    <p id="demo"></p>

    </body>
    </html> 
    quando faccio ripartire il timer me lo trovo con l'ora aggiornata, io invece vorrei fermare il timer e alla ripartenza che riparta da dove l'avevo fermato senza che si aggiorni all'ora attuale.
    So che le funzioni time prendono come riferimento il time stamp quindi quando faccio ripartire il timer stoppato lui prende in considerazione il time stamp quindi sempre il tempo che è passato e quindi si aggiorna al time corrente a me servirebbe per mettere in pausa questo countdown
    Codice PHP:
    /*
    Author: Robert Hashemian
    [url]http://www.hashemian.com/[/url]

    You can use this code in any manner so long as the author's
    name, Web address and this disclaimer is kept intact.
    ********************************************************
    Usage Sample:

    <script language="JavaScript">
    TargetDate = "12/31/2020 5:00 AM";
    BackColor = "palegreen";
    ForeColor = "navy";
    CountActive = true;
    CountStepper = -1;
    LeadingZero = true;
    DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
    FinishMessage = "It is finally here!";
    </script>
    <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
    */

    function calcage(secsnum1num2) {
      
    = ((Math.floor(secs/num1))%num2).toString();
      if (
    LeadingZero && s.length 2)
        
    "0" s;
      return 
    "[b]" "[/b]";
    }

    function 
    CountBack(secs) {
      if (
    secs 0) {
        
    document.getElementById("cntdwn").innerHTML FinishMessage;
        return;
      }
      
    DisplayStr DisplayFormat.replace(/%%D%%/gcalcage(secs,86400,100000));
      
    DisplayStr DisplayStr.replace(/%%H%%/gcalcage(secs,3600,24));
      
    DisplayStr DisplayStr.replace(/%%M%%/gcalcage(secs,60,60));
      
    DisplayStr DisplayStr.replace(/%%S%%/gcalcage(secs,1,60));

      
    document.getElementById("cntdwn").innerHTML DisplayStr;
      if (
    CountActive)
        
    setTimeout("CountBack(" + (secs+CountStepper) + ")"SetTimeOutPeriod);
    }

    function 
    putspan(backcolorforecolor) {
     
    document.write("<span id='cntdwn' style='background-color:" backcolor 
                    
    "; color:" forecolor "'></span>");
    }

    if (
    typeof(BackColor)=="undefined")
      
    BackColor "white";
    if (
    typeof(ForeColor)=="undefined")
      
    ForeColor"black";
    if (
    typeof(TargetDate)=="undefined")
      
    TargetDate "12/31/2020 5:00 AM";
    if (
    typeof(DisplayFormat)=="undefined")
      
    DisplayFormat "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
    if (
    typeof(CountActive)=="undefined")
      
    CountActive true;
    if (
    typeof(FinishMessage)=="undefined")
      
    FinishMessage "";
    if (
    typeof(CountStepper)!="number")
      
    CountStepper = -1;
    if (
    typeof(LeadingZero)=="undefined")
      
    LeadingZero true;


    CountStepper Math.ceil(CountStepper);
    if (
    CountStepper == 0)
      
    CountActive false;
    var 
    SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 990;
    putspan(BackColorForeColor);
    var 
    dthen = new Date(TargetDate);
    var 
    dnow = new Date();
    if(
    CountStepper>0)
      
    ddiff = new Date(dnow-dthen);
    else
      
    ddiff = new Date(dthen-dnow);
    gsecs Math.floor(ddiff.valueOf()/1000);
    CountBack(gsecs); 

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.