jquery无限滚动“重置”
我正在为网站使用无限滚动 jquery 插件 ( https://github.com/paulirish/infinite -scroll )
一切都很好,除了我的页面是一个搜索所以...发生的是:
1)你进入页面,浏览器自动定位你并给你返回一个项目列表(例如酒吧) ) 大约你...需要无限滚动以避免此列表的分页。一切都正常,直到这里......除了我可以到达“无限页面的末尾”并且插件从滚动中“解除绑定”这一事实。
2)现在....当您想在输入文本中手动插入地址时,您可以自由地执行...您写下您的地址,然后按回车键...并使用ajax(无页面刷新)...我会寻找纬度/经度,找到地址,更改无限滚动的导航链接...并且,我感觉很愚蠢,但我无法找到一种方法“重新激活”或“重新绑定”插件到事件......所以我的“新搜索结果”没有新的“无限滚动”实例...
(页面“拆分”正确并正确返回尝试更改“page=NUMBER”的json)
这就是控制台中发生的情况:
["math:", 0, 468]
jquery.infinitescroll.min.js:20["heading into ajax",
Array[2]
0 : "/ajax/getCoworkings/?page="
1 : "&latitude=52.5234051&longitude=13.4113999&distance=12"
length : 2
__proto__ : Array[0]
]
jquery.infinitescroll.min.js:20["Using JSON via $.ajax() method"]
jquery.infinitescroll.min.js:20["Error", "end"]
jquery.infinitescroll.min.js:20["Binding", "unbind"]
在“取消绑定”之后,我无法再次绑定它,因此在我的下一个搜索结果上无限滚动........
I'm using the infinite scroll jquery plugin for a website ( https://github.com/paulirish/infinite-scroll )
Everything is fine except that my page is a search so...what happen is:
1) you go on the page, browser auto-locates you and give you back a list of items (eg. bars) around you...Infinite scroll is needed to avoid pagination for this list. Everything works until here...except the fact that i could reache the "end-of-the-infinite-page" and the plugin "unbinds" itself from the scroll.
2) Now....when you want to manually insert an address in the input text, you are free to do it...you write your address, and press enter...and with ajax (no page refresh)...i'll look for lat/lon, locate the address, change the navigation link for the infinite scroll....and,i feel dumb, BUT i can't figure out a way to "reactivate" or "re-bind" the plugin to the event....So my "new search results" do not have a fresh "infinite scroll" instance...
(page "split" correctly and correctly returns a json trying changing "page=NUMBER")
This is what happens in the console:
["math:", 0, 468]
jquery.infinitescroll.min.js:20["heading into ajax",
Array[2]
0 : "/ajax/getCoworkings/?page="
1 : "&latitude=52.5234051&longitude=13.4113999&distance=12"
length : 2
__proto__ : Array[0]
]
jquery.infinitescroll.min.js:20["Using JSON via $.ajax() method"]
jquery.infinitescroll.min.js:20["Error", "end"]
jquery.infinitescroll.min.js:20["Binding", "unbind"]
After the "unbind" i'm not able to bind it again and therefore have the infinit scroll on my next search results........
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
infinitescroll 通过
$.data
将其所有实例数据存储在元素本身上,因此删除该实例数据是完全重置 infinitescroll 的唯一可靠方法。这两行应该能够彻底摧毁无限滚动。
// 现在无限滚动可以正常重新初始化,而不会因前一个实例而出现任何冲突或问题。
请注意,截至 2012 年 6 月,以前的答案都不适用于最新版本的 jquery.infinitescroll (v2.0)
infinitescroll stores all of its instance data on the element itself via
$.data
, so removing that instance data is the only sure-fire way to totally reset infinitescroll.These two lines should do the trick of cleanly destroying infinitescroll.
// now infinite scroll may be reinitialized normally without any conflicts or cruft lying around from the previous instance.
NOTE that as of June 2012, none of the previous answers worked for me with the latest version of jquery.infinitescroll (v2.0)
解决了。
我已经添加:
函数中。
在第 228 行的
这可能不是最好的方法,但这正是我所需要的。
我现在所做的基本上就是您的建议:
1.
2.
...无需修改“pathParse”值
但那是因为我正在修改选择器(下一个/导航)
之前,使用 jQuery。
Solved.
i've added:
in function
on line 228.
Probably that's not the best way of doing this, but it's exactly what i needed.
And what i do -now- is basically what you suggested:
1.
2.
...without the need to modify the "pathParse" values
but that's because i'm modifying the selectors (next/nav)
before, with jQuery.
这里没有提到,但是(无论如何在我的 Infinite Scroll 版本中)您还必须设置两个变量才能重新实例化 InfiniteScroll 才能工作。您还必须重新绑定它。这是代码:
It isn't mentioned here, but (in my version of Infinite Scroll anyway) you also have to set two variables for the re-instantiaion of InfiniteScroll to work. You also have to Rebind it. Here is the code:
在尝试其他解决方案无济于事后,这对我有用:
参考文档的 1/4: http://www.infinite-scroll.com/infinite-scroll-jquery-plugin/
After trying the other solutions to no avail, this worked for me:
Reference 1/4 down the docs: http://www.infinite-scroll.com/infinite-scroll-jquery-plugin/
我必须做类似的事情,因为我的代码根据用户操作更新目标网址,而不仅仅是依赖计数器。
我最终实现了以下重置方法,然后可以使用 $container('reset'); 调用该方法
我还实现了一个私有方法来重置悬停消息,否则它将继续给出“没有更多页面”通知。
I've had to do something similar since my code updates the destination url depending on user action rather than just relying on a counter.
I ended up implementing the following reset method that I can then call using $container('reset');
I also implemented a private method to reset the hover message since otherwise it would continue to give a "no more pages" notification.
假设您创建了无限滚动,例如:
您不能简单地完全销毁实例吗:
本质上,如果您没有定义 pathParse,脚本会尝试自行解决它。如果您这样做,那么它会使用您提供的内容。它不是很优雅,更像是一种黑客行为,但目前无限滚动并不严格支持更改 pathParse 。
Presuming you created infinite scroll like:
Could you not then simply completely destroy the instance:
Essentially if you don't define pathParse, the script tries to work it out itself. If you do then it uses what you provide. Its not very elegent, more of a hack than anything but changing pathParse isn't strictly supported in infinite-scroll at the moment.
项目 3)
}
也不起作用。至少使用最新版本。砖石工抱怨
'无法在初始化之前调用砌体上的方法;尝试调用方法“reload”
The item 3)
}
Did not work as well. At least with the latest version. The masonry complains about
'cannot call methods on masonry prior to initialization; attempted to call method 'reload''
您只需将以下代码添加到无限滚动声明中即可做到这一点。
注意不在infinitescroll.js 文件中,它应该在您的自定义无限滚动声明中。
you can do this by just adding the following code into your infinite scroll declaration.
Note not in infinitescroll.js file, it should be in your custom infinite scroll declaration.