JQuery:如何仅在完成调整大小后才调用 RESIZE 事件? [英] JQuery: How to call RESIZE event only once it's FINISHED resizing?

查看:36
本文介绍了JQuery:如何仅在完成调整大小后才调用 RESIZE 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览器窗口完成调整大小后如何调用函数?

我正在尝试这样做,但遇到了问题.我正在使用 JQuery Resize 事件函数:

I'm trying to do it like so, but am having problems. I'm using the JQuery Resize event function:

$(window).resize(function() {
  ... // how to call only once the browser has FINISHED resizing?
});

但是,如果用户手动调整浏览器窗口的大小,则该函数会连续调用.也就是说,它可能会在很短的时间内调用这个函数几十次.

However, this function is called continuously if the user is manually resizing the browser window. Which means, it might call this function dozens of times in short interval of time.

如何仅调用一次调整大小功能(浏览器窗口完成调整大小后)?

How can I call the resize function only a single time (once the browser window has finished resizing)?

更新

也无需使用全局变量.

推荐答案

这里是一个使用 jh 指令的例子

您可以将引用 ID 存储到任何 setInterval 或 setTimeout.像这样:

You can store a reference id to any setInterval or setTimeout. Like this:

var loop = setInterval(func, 30);

// some time later clear the interval
clearInterval(loop);

这篇关于JQuery:如何仅在完成调整大小后才调用 RESIZE 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆