gpt4 book ai didi

jquery - xhr.upload.onProgress 多久触发一次?

转载 作者:太空狗 更新时间:2023-10-29 15:29:09 25 4
gpt4 key购买 nike

我在通过 XHR 上传文件时订阅了 onProgress 事件。我的进度条是动画的(通过 jQuery)以提供更好的视觉美感。

onProgress 似乎触发得非常快,所以我想知道它实际触发的频率,以便我可以以某种方式设计一个过程,通过该过程我可以限制对此的响应,以便我可以有一个连续的动画进度条

最佳答案

虽然扩展 jQuery 可能是有益的;对于这种简单的扩展 jQuery 的东西来说,不值得开销。限制函数调用的有效解决方案可以写成:

xhr.upload.onprogress = function(event) {
// limit calls to this function
if (!this.NextSecond) this.NextSecond = 0;
if (Date.getTime() < this.NextSecond) return;
this.NextSecond = Date.getTime() + 1000;

// this code gets executed at least one second apart from the last time
}

关于jquery - xhr.upload.onProgress 多久触发一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6777005/

25 4 0
文章推荐: c中的字符数组消隐
文章推荐: javascript - touches 和 targetTouches 的区别
文章推荐: android - RoundedBitmapDrawable 和 TransitionDrawable
文章推荐: jquery - CSS 选择器查找具有指定