0

I want to get current iscroll item's id when an item comes in the viewport.

Ex: if element "G" come in the view, how can i get it's id. Here is my html code:

<div id="wrapper">
  <ul>
    <li id='a'>A</li>
    <li id='b'>B</li>
    <li id='c'>C</li>
    <li id='d'>D</li>
    <li id='e'>E</li>
    <li id='f'>F</li>
    <li id='g'>G</li>
   </ul>
</div>

And my js: var myScroll = new iScroll('wrapper');

Can anyone help me? Thanks in advance.....

Zana
  • 19
  • 1
  • 7

1 Answers1

0
var myScroll = new iScroll("wrapper", {
    hScroll : false,
    vScroll : true,
    snap : 'li',
    momentum : true,
    hScrollbar : false,
    vScrollbar : false,
    onScrollEnd: function() {
        var elementIndex = Number(this.currPageY);
        var scrollerElem = $("#wrapper").children()[0];
        var itemId = $(scrollerElem)[0].children[elementIndex].id;
        console.log(itemId);
   }
});
// Hope This Helps
wOlVeRiNe
  • 545
  • 1
  • 4
  • 21
  • It is but obvious that if you do not use snap the above piece of code would just console log as "1". Please let me know if this works for you. If you do not want to snap your elements. please specify the "viewport" that you were talking about. Where would it be positioned and all. – wOlVeRiNe Jun 13 '13 at 12:53