How do I detect with Refresh() is finished?

44 views
Skip to first unread message

Wade McDaniel

unread,
Jul 28, 2015, 6:22:01 PM7/28/15
to iScroll
Greetings,

I have an iscroll in the page using the iscroll-inifinite.js library

var iscroller = new IScroll(pm.radio.$tracks.parent().get(0), {
    scrollX
: true,
    scrollY: false,
    deceleration: 0.0005,
    eventPassthrough: true,
    scrollbars: false
});

At some point I add an <li> to the iscroll <ul> along with refreshing ads in the page and whatnot.

// add element to <ul> and set width of container
// start ads loading
window
.setTimeout("iscroller.refresh();", 0);
window
.setTimeout("iscroller.scrollToElement(document.getElementById('last-list-element'));", 200);

My problem is that on Mobile devices sometimes if I run this code quickly the list scrolls to the first element instead of the last element. I believe this is because the scrollToElement() function is being called before the refresh() function is finished with it's calculations.

Questions:
  1. Am I correct with my analysis of the cause of the problem?
  2. How do I fix this so every time it behaves the same way?

Thank you for your help!
-wade


Wade McDaniel

unread,
Jul 28, 2015, 6:32:49 PM7/28/15
to iScroll, wmcd...@wolfgangsvault.com
Sorry, in my code snippet please change "pm.radio.$tracks.parent().get(0)" to "document.getElementById("list")". Thanks!
Reply all
Reply to author
Forward
0 new messages