I'm making a mobile website with jQtouch and iScroll.
I wan't to get multiple scrollable areas with iScroll, but only of the lists works with iScroll...
I tried with this:
var scroll1, scroll2;
function loaded() {
scroll1 = new iScroll('wrapper');
scroll2 = new iScroll('list_wrapper');
}
But without luck. Anyone have a solution that's working?
My html:
<div id="wrapper">
<ul>
<li><a href="#">Test</a></li>
</ul>
</div>
<div id="list_wrapper">
<ul>
<li><a href="#">Test</a></li>
</ul>
</div>
I'm using this approach.
Html:
<div class="carousel" id="alt-indie">
<div class="scroller">
<ul>
<li></li>
// etc
</ul>
</div>
</div>
JS:
$('.carousel').each(function (index) {
new iScroll($(this).attr('id'), { /* options */ });
});
so anything with the class of "carousel" will become a slider.
Your html seems correct,
make sure 'loaded' function is being called as wel.
Something like this:
document.addEventListener('DOMContentLoaded', loaded, false);
hope that helps.
var scroll1, scroll2;
$("#you_might_like_index").live("pageshow", function() {
setTimeout(function(){scroll1 = new iScroll('wrapper');}, 0);
setTimeout(function(){scroll2 = new iScroll('list_wrapper');}, 0);
});
<div data-role="page" id="you_might_like_index">
<div id="wrapper">
<div id="scroller">
<ul>
<li><a href="#">Test</a></li>
</ul>
</div>
</div>
<div id="list_wrapper">
<div id="scroller">
<ul>
<li><a href="#">Test</a></li>
</ul>
</div>
</div>
</div>
This answer might be a bit late... but since I was stuck on the same problem, here's my solution, which works great. Note: This solution requires jquery, but I am using it anyway.
The script part:
function iscroller_init () {
var iscroller = $('.iscroller');
iscroller.each(function(index){
$(this).addClass('iscroller'+index).attr('iscroller_id','iscroller'+index);
var tmpfnc = new Function('var myScroll'+index);
tmpfnc();
var tmpfnc = new Function('myScroll'+index+' = new IScroll(\'.iscroller'+index+'\', { mouseWheel: true });');
tmpfnc();
});
}
function iscroller_reinit (el) {
var el = $(el);
var iscroller = $('.iscroller');
var i = iscroller.index(el);
var tmpfnc = new Function('var myScroll'+i+' = new IScroll(\'.iscroller'+i+'\', { mouseWheel: true });');
tmpfnc();
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
$(document).ready(function(){
if ($('.iscroller').length > 0) iscroller_init ();
});
The html:
<div class="scrollholder fl">
<div class="iscroller">
<div class="scroller">
<ul>
<li>Pretty row 1</li>
<li>Pretty row 2</li>
<li>Pretty row 3</li>
<li>Pretty row 4</li>
.....
<li>Pretty row 47</li>
<li>Pretty row 48</li>
<li>Pretty row 49</li>
<li>Pretty row 50</li>
</ul>
</div>
</div>
</div>
where the parent <div class="scrollholder fl">
is the parent div, which can be positioned where you want, and multiple times.
Info: The class "fl" works as css separator for "float:left;"
in my case and is not corresponding to any iscroll function.
The second function iscroller_reinit (el)
is for reinitialisation of specified single iscroller, may be fired after the container was loaded by ajax request.
来源:https://stackoverflow.com/questions/9976972/multiple-iscroll-elements-on-same-page