2016-07-27 110 views
1

我在magento中使用dropzone.js上传文件。进度条工作正常,但我也想显示进度百分比。以下功能正在为一个范围添加样式。如何在dropzone.js中显示上传进度百分比

uploadprogress: function(a, b) { 
       var c, d, e, f, g; 
       if (a.previewElement) { 
        for (f = a.previewElement.querySelectorAll("[data-dz-uploadprogress]"), g = [], d = 0, e = f.length; e > d; d++) c = f[d], g.push("PROGRESS" === c.nodeName ? c.value = b : c.style.width = "" + b + "%"); 
        return g 
       } 
      }, 

它在下面的html中添加style =“width:xx%”。

我也想显示%结果哪个克在上面的代码在span中返回作为文本,以便用户也可以看到数字。

回答

2

假设你有一个像这样的,例如你的进度条跨度:

<div class="progress"> 
    <div class="progress-bar progress-bar-primary" role="progressbar" data-dz-uploadprogress> 
     <span class="progress-text"></span> 
    </div> 
</div> 

你应该定义你的uplaodprogressfunction如下:

uploadprogress: function(file, progress, bytesSent) { 
    if (a.previewElement) { 
     var progressElement = file.previewElement.querySelector("[data-dz-uploadprogress]"); 
     progressElement.style.width = progress + "%"; 
     progressElement.querySelector(".progress-text").textContent = progress + "%"; 
    } 
} 
+0

这个效果很好。我想添加到这个解决方案的解决方案,所以谁读这个谁可能想知道它在选项中,所以要添加到这些选项这样做:'Dropzone.options.dropzoneIDHere = {uploadresolving:function(file,progress,bytesSent ){ } };' – fungusanthrax

相关问题