Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Preloading Modificato

  1. #1
    Utente di HTML.it L'avatar di MM88
    Registrato dal
    Jun 2003
    Messaggi
    567

    Preloading Modificato

    Ciao, volevo creare un preloading che caricasse tutte le foto presenti in una cartella, in modo che fossero disponibili ad altri script presenti nella mia pagina.

    Ho quindi trovato un javascript e l'ho modificato con PHP, in modo che costruisse l'array con i nomi delle foto.

    Vi chiedo: visto che le immagini nello script originale venivano mostrate in uno slideshow, cosa devo eliminare da questo script, in modo che carichi solamente le pagine nella cache del client?


    grazie


    codice:
    <script language="JavaScript" type="text/JavaScript"> 
        // Set slideShowSpeed (milliseconds)
        var slideShowSpeed = 5000
    
        // Duration of crossfade (seconds)
        var crossFadeDuration = 3
    
        // Specify the image files
        var Pic = new Array() // don't touch this
        // to add more images, just continue
        // the pattern, adding to the array below
    
    <? 
    $absolute_path = "images";
    $dir = opendir($absolute_path); 
    $f=array(); 
    
    while($file = readdir($dir)) 
       if (($file != "..") and ($file != ".")) 
           $f[]=$file; 
    
    
    unset($file,$dir); 
    sort($f); 
    
    $i = 0;
    
    foreach($f as $file) 
        echo "Pic[$i] = '$file'\n";
    
    $i++;
    ?>
        
        var t
        var j = 0
        var p = Pic.length
    
        var preLoad = new Array()
        for (i = 0; i < p; i++){
           preLoad[i] = new Image()
           preLoad[i].src = Pic[i]
        }
    
        function runSlideShow(){
           if (document.all){
              document.images.SlideShow.style.filter="blendTrans(duration=2)"
              document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
              document.images.SlideShow.filters.blendTrans.Apply()      
           }
           document.images.SlideShow.src = preLoad[j].src
           if (document.all){
              document.images.SlideShow.filters.blendTrans.Play()
           }
           j = j + 1
           if (j > (p-1)) j=0
           t = setTimeout('runSlideShow()', slideShowSpeed)
        }
        </script>

  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649

    Re: Preloading Modificato

    codice:
    <script language="JavaScript" type="text/JavaScript"> 
        // Specify the image files
        var Pic = new Array() // don't touch this
        // to add more images, just continue
        // the pattern, adding to the array below
    
    <? 
    $absolute_path = "images";
    $dir = opendir($absolute_path); 
    $f=array(); 
    
    while($file = readdir($dir)) 
       if (($file != "..") and ($file != ".")) 
           $f[]=$file; 
    
    
    unset($file,$dir); 
    sort($f); 
    
    $i = 0;
    
    foreach($f as $file) 
        echo "Pic[$i] = '$file'\n";
    
    $i++;
    ?>
    
        var p = Pic.length
    
        var preLoad = new Array()
        for (i = 0; i < p; i++){
           preLoad[i] = new Image()
           preLoad[i].src = Pic[i]
        }
    
    </script>
    ciao

  3. #3
    Utente di HTML.it L'avatar di MM88
    Registrato dal
    Jun 2003
    Messaggi
    567
    Grazie Xinod per l'aiuto.

    Posso aggiungere qualche script di controllo in modo da verificare che il caricamento avvenga regolarmente?

    Perché nella barra di stato non leggo niente.


    grazie

  4. #4
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    prova
    codice:
        ...
        var preLoad = new Array()
        for (i = 0; i < p; i++){
           preLoad[i] = new Image()
           preLoad[i].onload=(function(k){return function(){alert('caricata immagine'+k+':"'+Pic[k]+'"');}})(i)
           preLoad[i].src = Pic[i]
        }

  5. #5
    o rigirando la frittata:
    Codice PHP:
    for (0pi++){
        
    preLoad[i] = new Image();
        
    preLoad[i].onerror=(function(k){return function(){alert('immagine non caricata '+k+':"'+Pic[k]+'"');}})(i);
        
    preLoad[i].src Pic[i];

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

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.