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

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

问题描述

我希望这个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.

例如,当您第一次收到resize事件时,将标志设置为true表示用户当前正在调整大小。设置超时以在1秒后调用实际的resize事件处理程序。然后,只要此标志为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.

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

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