滚动到Iscroll中的元素 [英] Scroll to element in Iscroll

查看:231
本文介绍了滚动到Iscroll中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在jquery移动版Iscroll中使用滚动到元素"功能
但它不起作用
这就是我的脚本的样子
我在这里尝试过 MyJsfiddle

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

推荐答案

您快到了,对scrollTo的调用缺少一个参数.定义为:

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

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

这是一个滚动到单击项的jFiddle: http://jsfiddle.net/CKSYJ/73 /

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

基本上,代码是:

$('#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防止在页面转换前滚动到顶部?

Jquery Mobile返回按钮滚动到顶部

这篇关于滚动到Iscroll中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆