简体   繁体   English

在滚动位置之前添加元素,并且不影响当前滚动/视图

[英]Add element before scroll position, and not affect current scroll / view

I'm trying to achieve the behaviour – for example – the Twitter Mac client: 我正在尝试实现这种行为-例如,Twitter Mac客户端:

I got a box I can scroll in (overflow Y, fixed height), and I got several blocks inside. 我有一个可以滚动的框(溢流Y,固定高度),里面有几个方块。 I want to add a new block before all others, but make it invisible to the user: so when there's a new block added before, user have to scroll to the top to view it. 我想在所有其他块之前添加一个新块,但使用户看不到它:因此,当之前添加新块时,用户必须滚动到顶部才能查看。

How would you achieve this? 您将如何实现? (JS powered of course, but must be touch-devices ready, and iP* do not run JS while scrolling). (当然,JS支持,但必须准备好触摸设备,并且iP *在滚动时不运行JS)。

Thanks! 谢谢!

I tried out changing the scrollTop after the element is added, and it seems to work fine on Chrome. 添加元素后,我尝试更改scrollTop,它似乎在Chrome上正常运行。 You would have to check it out in other browsers. 您将不得不在其他浏览器中签出。

$(document).scrollTop($(document).scrollTop() + elmHeight);

http://jsfiddle.net/ub5BU/ http://jsfiddle.net/ub5BU/

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

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