I initialize/refresh the iScroll instances on the pageshow
and orientationchange
events. I set a class on data-role="content"
divs that I want to be scrollable (in this instance I used the .content
class).
var myScroll = [];
$(document).delegate('[data-role="page"]', 'pageshow', function () {
if ($.mobile.activePage.find('.content').length > 0) {
if (this.id in myScroll) {
myScroll[this.id].refresh();
} else {
myScroll[this.id] = new iScroll($.mobile.activePage.find('.content')[0].id, {
hScroll : false,
vScroll : true,
hScrollbar : false,
vScrollbar : true,
fixedScrollbar : true,
fadeScrollbar : false,
hideScrollbar : false,
bounce : true,
momentum : true,
lockDirection : true
});
}
}
});
$(window).bind('orientationchange', function () {
if ($.mobile.activePage[0].id in myScroll) {
myScroll[$.mobile.activePage[0].id].refresh();
}
});