简体   繁体   中英

JScroll: Change nextHref after ajax changed tab and URI

JScroll can't see when the javascript changed window history with pushState .

I added JScroll for posts on index page. The default URL is localhost for example. And when there is no path after, the default posts will be loaded and jscroll will work as it should have.

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.

But in JScroll, it still leaves old href and loads old data. 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" .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM