The iScroll documentation shows a typical iScroll setup like the one below.
var myScroll;
function loaded() {
setTimeout(function () {
myScroll = new iScroll('wrapper');
}, 100);
}
window.addEventListener('load', loaded, false);
My question is how do I call the scroller? If I use:
var currentItem = 5;
myScroll.scrollToElement('.nav > li:nth-child('+currentItem+')', 300);
I get an error.
Uncaught TypeError: Cannot call method 'scrollToElement' of undefined
I suppose you need to use the variable name you assigned the iScroll to:
and not
Update:
According to your latter tests, it obviously was a timing error. You proably called
myScroll.scrollToElementbefore the timeout function was executed.