拖动调整大小手柄时多次触发调整大小事件 [英] Resize event firing multiple times while dragging the resize handle

查看:58
本文介绍了拖动调整大小手柄时多次触发调整大小事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这个jQuery插件可以工作,但是没有:

I was hoping this jQuery plug-in would work, but it didn't:

http://andowebsit.es/blog/noteslog.com/post/how-to-fix-the-resize-event-in-ie (旧链接为noteslog.com/post/how-to-fix-the-resize-event-in-ie).

http://andowebsit.es/blog/noteslog.com/post/how-to-fix-the-resize-event-in-ie (old link was noteslog.com/post/how-to-fix-the-resize-event-in-ie ).

我在他的网站上添加了评论,但评论已被审核,因此您可能还没有看到它.

I added a comment to his site, but they're moderated, so you might not see it yet.

但是无论如何,让我解释一下我的愿望.我想要调整大小"当用户暂停调整大小和/或完成调整大小时触发的事件类型,而不是 时,用户正在主动拖动浏览器的窗口调整大小手柄.我有一个需要运行的相当复杂且耗时的 OnResizeHandled 函数,但不能运行100次,只是因为用户将窗口扩大了100px,并且事件被触发了一个永远无法移动的像素.我猜最好的办法是在用户完成调整大小后对其进行处理.

But anyhow, let me explain my desire. I want a "resize" type of event to be fired when the user either pauses his resize, and/or completes his resize, not while the user is actively dragging the browser's window resize handle. I have a fairly complex and time consuming OnResizeHandled function I need to run, but not run 100 times just because the user widened the window by 100px and the event was fired for ever pixel of movement. I guess a best bet would be to handle it once the user has completed the resize.

推荐答案

从并发解决方案中借鉴一些想法,以管理来自浏览器的大量事件.

Borrow some ideas from concurrency solutions to manage the flood of events coming from the browser.

例如,当您第一次获得调整大小事件时,请将标志设置为true,以指示用户当前正在调整大小.设置超时以在1秒后调用实际的调整大小事件处理程序.然后,只要此标志为true,就忽略resize事件.然后,在实际的处理程序中,完成所有操作并纠正后,将标志设置回false.

For example, when you first get a resize event, set a flag to true indicating that the user is currently resizing. Set a timeout to call the actual resize event handler after 1 second. Then, whenever this flag is true, ignore the resize event. Then, in the actual handler, once everything is done and correct, set the flag back to false.

这样,您仅每秒处理一次最新事件(或其他一段时间,具体取决于您的要求).如果用户在调整大小的过程中暂停,它将进行处理.如果用户完成操作,它将进行处理.

That way you only process the latest event once every second (or some other period of time depending on your requirements). If the user pauses in the middle of resizing, it will process. If the user finished, it will process.

这可能不适合您,但是还有许多其他使用锁的方法可能会更有用.

This might not be suitable for you, but there are many other ways of using locks that might be more helpful.

这篇关于拖动调整大小手柄时多次触发调整大小事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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