jQuery 结合 .ready 和 .resize
当调整窗口大小时,我的 jQuery .ready 函数中的一些(嗯,几乎全部)代码也适用,因为它是布局工作。但是,由于它是相同的代码,我如何“组合”这两个函数,以便我的代码不会重复(并且维护起来很混乱)?
谢谢!
Some (well, nearly all) of my code that is in my jQuery .ready function also applies when the window is resized, as it's layout work. However, since it's the same code, how could I "combine" the two functions, so that my code doesn't repeat itself (and be a mess to maintain)?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另一种技术是将
.trigger()
一个事件放在另一个事件中:如果您将代码放在页面底部以避免需要
$(document).ready
,它变得更简单:Another technique is to
.trigger()
one event inside the other:If you put your code at the bottom of the page to avoid needing
$(document).ready
, it gets even simpler:又一个更好的选择
One more better option
像这样的东西??
Something like this??
以下代码可能有助于在
调整大小准备就绪
之后执行操作。以下是在调整大小时运行代码的问题。
The following code might be helpful to do things after
resize is ready
.Here is the issue with the following that the code is running while resize is under going.