使用HTML5上传文件时显示简单的GIF

问题描述:

使用HTML5上传文件,可以检查文件是否正在上传?最终我想展示一个简单的gif,像一个进度条,但没有任何dificult计数器/数学,所以这只是一个简单的gif;使用HTML5上传文件时显示简单的GIF

enter image description here

http://jsfiddle.net/DFT78/

,并在文件上传我想这再次隐藏。我想知道的是; 如何检查文件是否正在上传?

代码(HTML5ROCKS)

<style> 
    .thumb { 
    height: 75px; 
    border: 1px solid #000; 
    margin: 10px 5px 0 0; 
    } 
</style> 

<input type="file" id="files" name="files[]" multiple /> 
<output id="list"></output> 

<script> 
    function handleFileSelect(evt) { 
    var files = evt.target.files; // FileList object 

    // Loop through the FileList and render image files as thumbnails. 
    for (var i = 0, f; f = files[i]; i++) { 

     // Only process image files. 
     if (!f.type.match('image.*')) { 
     continue; 
     } 

     var reader = new FileReader(); 

     // Closure to capture the file information. 
     reader.onload = (function(theFile) { 
     return function(e) { 
      // Render thumbnail. 
      var span = document.createElement('span'); 
      span.innerHTML = ['<img class="thumb" src="', e.target.result, 
          '" title="', escape(theFile.name), '"/>'].join(''); 
      document.getElementById('list').insertBefore(span, null); 
     }; 
     })(f); 

     // Read in the image file as a data URL. 
     reader.readAsDataURL(f); 
    } 
    } 

    document.getElementById('files').addEventListener('change', handleFileSelect, false); 
</script> 
+1

请参阅此http://*.com/a/8858040/405398并使用XHR的进度事件。 – 2013-03-19 12:56:00

我不知道的 “正确” 的方式来做到这一点。但是我在上传页面中使用了一个Iframe,然后我可以在上传工作的同时在其中放置一个gif。