如何在 dropzone.js 中显示上传进度百分比
How to show upload progress percentage in dropzone.js
我在 magento 中使用 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中添加样式="width:xx%"。
我还想将上面代码中 g return 的 % 结果显示为文本,以便用户也可以看到数字。
假设您的进度条中有一个跨度,例如:
<div class="progress">
<div class="progress-bar progress-bar-primary" role="progressbar" data-dz-uploadprogress>
<span class="progress-text"></span>
</div>
</div>
您应该按如下方式定义上传进度函数:
uploadprogress: function(file, progress, bytesSent) {
if (file.previewElement) {
var progressElement = file.previewElement.querySelector("[data-dz-uploadprogress]");
progressElement.style.width = progress + "%";
progressElement.querySelector(".progress-text").textContent = progress + "%";
}
}
给猫剥皮的方法有很多...我的实现似乎有什么问题吗?尽管百分比绝不是四舍五入的“10.12345678%”。
myDropzone.on("totaluploadprogress", function (progress) {
$("#the-progress-div").width(progress + '%');
$(".the-progress-text").text(progress + '%');
});
我在html中使用了这个:
<div id="the-progress-div">
<span class="the-progress-text"></span>
</div>
我在 magento 中使用 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中添加样式="width:xx%"。
我还想将上面代码中 g return 的 % 结果显示为文本,以便用户也可以看到数字。
假设您的进度条中有一个跨度,例如:
<div class="progress">
<div class="progress-bar progress-bar-primary" role="progressbar" data-dz-uploadprogress>
<span class="progress-text"></span>
</div>
</div>
您应该按如下方式定义上传进度函数:
uploadprogress: function(file, progress, bytesSent) {
if (file.previewElement) {
var progressElement = file.previewElement.querySelector("[data-dz-uploadprogress]");
progressElement.style.width = progress + "%";
progressElement.querySelector(".progress-text").textContent = progress + "%";
}
}
给猫剥皮的方法有很多...我的实现似乎有什么问题吗?尽管百分比绝不是四舍五入的“10.12345678%”。
myDropzone.on("totaluploadprogress", function (progress) {
$("#the-progress-div").width(progress + '%');
$(".the-progress-text").text(progress + '%');
});
我在html中使用了这个:
<div id="the-progress-div">
<span class="the-progress-text"></span>
</div>