BB Design
BB Design

Reputation: 705

Pass DOM element to iScroll function scrollToElement with eq

I am using the scrollToElement feature of iScroll to automatically scroll to an element. All I should have to do is "pass an element or a selector" (according to the docs), and this has worked for me before. In this more complex example, however:

$('div.entry-content > ul li a').on('click', function(){
    var numClicked=$(this).parent('li').index();
    $('h2:eq('+numClicked+')').css('color','#f00');
    scroller.scrollToElement($('h2:eq('+numClicked+')'), 1000);
});

...I am getting an error message. The CSS statement is working, so the H2 along with the EQ is getting to the right element. But when I try to pass the same thing to scrollToElement, it doesn't work. Is there a better way for me to reference the element?

Upvotes: 0

Views: 329

Answers (1)

BB Design
BB Design

Reputation: 705

iScroll would not accept the :eq part of my selector. So, I solved this by using jQuery to add a temporary class to the element using :eq, then passing the class to iScroll. Now it works fine.

Upvotes: 1

Related Questions