Multiple iScroll items on one page

I am making a mobile site with jQtouch and iScroll.

I would not get a few scrollable areas with iScroll, but only from lists it works with iScroll ...

I tried with this:

var scroll1, scroll2;
function loaded() {
   scroll1 = new iScroll('wrapper');
   scroll2 = new iScroll('list_wrapper');
}

But no luck. Does anyone have a solution that works?

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>
+5
source share
4 answers

I use 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 */ });
});

therefore, everything with the carousel class will become a slider.

+2
source

Your html seems right

make sure that the loaded function is called as a welcoming one.

Something like that:

document.addEventListener('DOMContentLoaded', loaded, false);

hope this helps.

0
source
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>
0

... , , . . jquery, .

script:

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 ();
});

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>

<div class="scrollholder fl"> div, , , . : "fl" css- "float:left;" - iscroll. iscroller_reinit (el) , , ajax.

0

All Articles