简体   繁体   English

iScroll + jQuery Mobile->动态Listview滚动位置问题

[英]iScroll + jQuery Mobile -> Dynamic Listview Scrolling Position Issue

I have a dynamically updated listview. 我有一个动态更新的列表视图。 I've get data from my JSON service, parse and dynamically injected to div. 我已经从JSON服务中获取数据,进行了解析并动态地注入了div。 The problem is; 问题是; after generating all data, scrolling is working but not completely. 生成所有数据后,滚动正常但不能完全滚动。 Imagine that, you press and scroll the listview up, if you remove hour finger from screen, listview position automatically turn back its start position. 想象一下,您按下并向上滚动列表视图,如果您从屏幕上移开了时针,列表视图位置会自动转回其起始位置。 I tried my iScroll and jQuery mobile with hard coded <ul><li> code, then it works. 我用硬编码的<ul><li>代码尝试了iScroll和jQuery mobile,然后它起作用了。

Here is the code below: 这是下面的代码:

     <script>
     var myScroll2;

     function loaded() {
myScroll2 = new iScroll('wrapper2');

    }

     document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
     document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded,   200); }, false);
      </script>

.. ..

    <div id="wrapper2"> 
    <div data-role="content">   
    <div id="panoListDetay"></div>
    </div>
    </div>

---and below code was to generata data for listview. ---和下面的代码是生成用于listview的数据。

    /*automatically upldated script*/
    /*called every 5 second*/
    <script>
    $(function update_twit(){
    $.ajax({
    url: "http://myweepage.org/service.json?q=getlast10data",
    dataType: 'jsonp',
    success: function(json_results){
        $("#notice_div").html(''); 
        $("#panoListDetay").html('');
        $('#panoListDetay').append('<ul id="tweetul" data-role="listview" data-theme="c"></ul>');
        listItems = $('#panoListDetay').find('ul');
        $.each(json_results.results, function(key) {
            html = '<h3>'+json_results.results[key].screen_name+'</h3><div class="ui-li-desc">'+json_results.results[key].text+'</div>';
            html += '<p class="ui-li-aside"><img WIDTH=12 HEIGHT=12 src="images/11-clock.png"/><strong> '+json_results.results[key].tarih.substring(11,16)+'</strong></p>';
            html +='<p class="ui-li"><img WIDTH=8 HEIGHT=13 src="images/07-map-marker.png"/> '+json_results.results[key].adres_data+'</p>';
            listItems.append('<li>'+html+'</li>');
        });
        $('#panoListDetay ul').listview();
        window.setTimeout(update_twit, 5000);
    },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
        window.setTimeout(update_twit, 20000);
    }
    });
    })
    </script>

Hi all I fixed this issue. 大家好,我解决了这个问题。 The problem is related with div=content's style. 问题与div = content的样式有关。

 <div id="wrapper2"> 
<!--<div data-role="content">-->  
<div id="panoListDetay"></div>
<!--</div>-->
</div>
// Append the HTML to your element inside your myScroll
setTimeout(function () {
       myScroll.refresh();
   }, 100);

There is no problem with using the data-role="content" 使用data-role =“ content”没问题

You should refresh your iscroll after appending the data 附加数据后,您应该刷新iscroll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM