jquery $(document).ready() 队列顺序
我有一个页面index.html,它扩展了base.html(django),并且每个页面都定义了$(document).ready。现在,我期望 base.html 中的那个先行,但我错了,index 中的那个是第一个,而 base.html 中的那个则在后面开始。我猜这是因为索引在基础之前完成加载,而不是 jquery 的某些默认行为,让子级在父级之前执行。我可以做些什么来改变这个订单吗?因为父级决定(取决于窗口大小)菜单应该是垂直的还是水平的,而子级则缩放 div 以占据窗口的其余部分。现在我希望在菜单就位后进行缩放。
I have a page index.html that extends base.html (django) and each of them has a $(document).ready defined. Now, I was expecting the one in base.html to go of first, but I was wrong, the one in index is first and the one in base.html starts after. I guess this is because index finishes loading before base, and not some default behavior of jquery, to have children execute before the parent. Can I do something to change this order? Because the parent decides (depending on window size) if the menu should be vertical or horizontal, and the child scales a div to occupy the rest of the window. Now I would like the scaling to occur after I have the menu in place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
理论上,您可以通过操作 jQuery.readyList 数组并移动内容来更改此设置,但您可能会有点盲目。相反,我建议将需要在其他脚本之后运行的脚本从
document.ready
切换到window.onload
,如下所示:看来您无论如何都想要这个,因为您正在处理窗口大小和缩放,并且这种情况发生在加载图像之后,所以您的缩放将是正确的,不会仍然发生变化。
You could theoretically change this by manipulating the
jQuery.readyList
array and moving things around, but you'd be poking a bit blind in there. Instead I'd recommend switching your script that needs to run after the others fromdocument.ready
towindow.onload
, like this:It seems you'd want this anyway, since you're dealing with window size and scaling, and this happens after the images are loaded, so your scale would be correct, not still changing.