非常奇怪的jquery问题
我试图在页面加载时运行一个函数,但它不起作用。我已经将它添加到我能想到的每个地方,唯一有效的方法是:
$("html").mousemove(function(event) {
$('#project_thumbs_container').masonry('reload');
});
我尝试过延迟,但我采用了上面的 hacky 方法:(
有没有人有任何建议为什么我的函数无法运行?
更新:
我正在使用 jquery 的 masonry。我的问题是当我加载使用 ajax 的 masonry 的页面时,它会在单个列中显示它们。 $('#project_thumbs_container').masonry('reload');
可以正确重置它,但它只能使用上面的 mousemove
方法。
I am trying to run a function on page load but its not working. I've added it in every place I can think of and the ONLY thing that works is:
$("html").mousemove(function(event) {
$('#project_thumbs_container').masonry('reload');
});
I've tried delays but I have resorted to the hacky above method :(
Does anyone have any suggestions as to why my function won't run?
UPDATE:
I am using masonry for jquery. My problem is when I load a page that uses masonry with ajax, it shows them in a single column. $('#project_thumbs_container').masonry('reload');
resets it properly, but it only works using the above mousemove
method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来您遇到了以下两个问题之一:
1) 格式错误的 HTML 导致错误,在使用文档 onReady 语法时不允许代码正确解析: $(function() { ... });
2) Masonry 可能会异步加载,这意味着“onReady”回调可能不是您想要使用的回调。您的 Ajax 调用看起来更像是这样:
It sounds like you have one of two problems:
1) Malformed HTML which is causing an error, which isn't allowing the code to parse correctly when using the document onReady syntax: $(function() { ... });
2) Masonry might be loading asynchronously, which means that the "onReady" callback might not be the one that you want to be using. Your Ajax call would look more like this:
除非有人有更好的答案,否则我只是在 ajax 调用完成后将代码放入我的
fadeIn();
代码片段中:似乎可以工作。
Unless someone has a better answer, I just put the code in my
fadeIn();
snippet after ajax call is complete:Seems to work.
尝试这样的事情。
您可以将此代码放在页面上的任何位置,只要依赖项已加载,它就应该可以工作。
Try something like this.
You can put this code anywhere on the page and it should work, as long as the dependencies have already been loaded.
只需将您的函数放入其中,
当您的页面加载时,该函数就会执行
Just put your function in this
when your page load the function will execute