Reputation: 2325
I am using iScroll to perform my scrolls in my webapp and are very happy with it. But in this case I need to autoscroll to a specific li at the page load, but am having no luck with it.
Here is what I am trying to do:
var myScroll;
function loaded () {
myScroll = new IScroll('#wrapper', { mouseWheel: true, click: true });
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
myScroll.scrollToElement(document.querySelector('#scroller li:nth-child(50)'), null, null, true);
If I insert a link like this:
<a href="javascript:myScroll.scrollToElement(document.querySelector('#scroller li:nth-child(50)'))">
Everything works as it should... what am I doing wrong?
Upvotes: 0
Views: 524
Reputation: 99
I suggest using the window.onload event to do the exact same thing you are doing in that function call It should look something like this:
window.onload = function() {
myScroll.scrollToElement(document.querySelector('#scroller li:nth-child(50)'), null, null, true);
}
here are more details about the onload event (you can even attach it to html elements)
Upvotes: 1