简体   繁体   中英

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

I'm trying to achieve the behaviour – for example – the Twitter Mac client:

I got a box I can scroll in (overflow Y, fixed height), and I got several blocks inside. 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).

Thanks!

I tried out changing the scrollTop after the element is added, and it seems to work fine on Chrome. You would have to check it out in other browsers.

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

http://jsfiddle.net/ub5BU/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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