3

I'm developing an infinite list using HTML5 on iPad with Retina. The idea is to render two pages then remove the first page and append next one to the bottom of the list. It works fine on Desktop Safari and Chrome but not on iPad.

There are two pages in the example. All the messages are the same 120px height but the very first one with 300px height. To reproduce the issue scroll to the very bottom and press a LoadMore button and you should notice that it jumps up and then to the correct position. It looks like there is a slight delay between scrolling and removing. Now all the messages are the same 120px height and if you scroll at the bottom and click button again there won't be any jumps and it will behave as expected. Press restart button to start again.

Link to the example.

The layout:

<div class="container"><div class="innerContainer">
  <div class="page">
    <div class="message" style="height:300px">...</div>
    <div class="message">...</div>
    <div class="message">...</div>
    <div class="message">...</div>
    <div class="message">...</div>
  </div>
  <div class="page">
    ...
  </div>
 </div>
</div>

Please note the behaviour is exactly the same if I use UL and LIs instead of DIVs.

The code of LoadMore button:

newScrollPosition = container.scrollTop()-firstPage.outerHeight();
container.scrollTop(newScrollPosition);   
innerContainer.append(newPage);
firstPage.remove();

It works fine when all the messages are the same height, but when any message has different height it jumps ugly.

Just remember that issue occurs only at the very bottom of the list.

I've tried the following ways of removing the firstPage but the outcome is always the same:

  • display:none
  • jquery remove
  • elem.parentNode.removeChild( elem )
  • absolute position with top and left outside of the screen
4

2 回答 2

1

我想出的最佳解决方法是将原生滚动 {overflow-scrolling:touch} 替换为 iScroll 5 库。它可以在 iPad 和桌面平台上运行而没有问题。

iScroll 使用 CSS3 过渡来代替原生滚动。

链接到示例。

我已经替换了以下代码

newScrollPosition = container.scrollTop() - firstPage.outerHeight(true);
container.scrollTop(newScrollPosition);

newScrollPosition = scroller.y + firstPage.outerHeight(true);
scroller.scrollTo(0, newScrollPosition);

更改 DOM 时刷新滚动条很重要。

链接到 iScroll 库。

于 2013-08-08T11:49:48.323 回答
1

如果您尝试过 jQuery.remove,您是否尝试过 slideUp?

前段时间我也遇到过类似的问题,如果从跳跃中它至少会停止,然后它会平稳滑动。

于 2013-08-05T14:00:33.227 回答