[英]JScroll: Change nextHref after ajax changed tab and URI
JScroll can't see when the javascript changed window history with pushState
. 当javascript使用pushState
更改窗口历史记录时,JScroll无法看到。
I added JScroll for posts on index page. 我为索引页面上的帖子添加了JScroll。 The default URL is localhost for example. 例如,默认URL是localhost 。 And when there is no path after, the default posts will be loaded and jscroll will work as it should have. 并且当之后没有路径时,将加载默认帖子,并且jscroll将按应有的方式工作。
But I have tabs on index page (new, top, hot), which change order of posts. 但是我在索引页面上有标签(新的,顶部的,热门的),这些标签可以更改帖子的顺序。 So when I click on a tab, it dynamically changes URL with window.history.pushState
, and sends request with new filter for showing posts. 因此,当我单击选项卡时,它会使用window.history.pushState
动态更改URL,并发送带有新过滤器的请求以显示帖子。
But in JScroll, it still leaves old href and loads old data. 但是在JScroll中,它仍然保留旧的href并加载旧的数据。 For example - I am scrolling on localhost/new , and when I change tab to localhost/top in JScroll nextHref
is "http://localhost:8000/new?page=3 div.infinite-scroll"
instead of "http://localhost:8000/top?page=1 div.infinite-scroll"
. 例如-我在localhost / new上滚动,当我在JScroll nextHref
tab更改为localhost / top时 , nextHref
是"http://localhost:8000/new?page=3 div.infinite-scroll"
而不是"http://localhost:8000/top?page=1 div.infinite-scroll"
。
How can I change it so it is synced with tabs? 如何更改它以使其与选项卡同步?
I found a solution. 我找到了解决方案。
After each change of tab I added 在每次更改标签后,我添加了
$('.infinite-scroll').removeData('jscroll').jscroll.destroy();
and called JScroll initializer again. 并再次调用了JScroll Initializer。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.