Scroll to element in Iscroll

2.6k Views Asked by At

I Trying to use the scroll to element function in the jquery mobile Iscroll
But its not working
This is what my script looks like
I tried here MyJsfiddle

$('[data-role="content"]').trigger('create');
$(".scroll-wrapper").iscrollview();
$(".scroll-wrapper").iscrollview('refresh');

    $('.chequeBanks').click(function(){
        $(".scroll-wrapper").iscrollview('refresh');
         var bankId=$(this).val();
         $('.accNumber').html($('.chequeBankDetailsSec .bankId-'+bankId+' .number').html());
         $('.details').show();
         $('.details').show();
         var x = $('.details').offset().left;
         var y = $('.details').offset().top;
        $(".scroll-wrapper").iscrollview("scrollTo", x,y, '1');
    });
1

There are 1 best solutions below

0
On

You are almost there, the call to scrollTo is missing an argument. It is defined as:

$("#scrollobject").iscrollview("scrollTo", x, y, time, relative);

Here is a jFiddle that scrolls to a clicked item: http://jsfiddle.net/CKSYJ/73/

Basically, the code is:

$('#test-list li').on('click', function(){   
    var pos = $(this).prev().offset().top;
    //alert(pos);
    $('#example-iscroll').iscrollview('scrollTo', 0, pos, 0, true);
    $('#example-iscroll').iscrollview('refresh');
});  

Some useful answers to similar questions can be found here:

jQuery Mobile prevent scroll-to-top before page transition?

Jquery Mobile go back button scrolls to top