神刀安全网

Scrollbear – A modern tool that maintains scroll position when images loaded

Scrollbear

Scrollbear is a tool that maintains the container scroll position when images loaded. Scrollbear is suitable in blog platforms where exist many photos and images. When images loaded, the scroll position will jump and cause a unfriendly experience. Scrollbear will trace the container height and maintain the scroll position when the images loaded and container height change.

Demo

Installation

npm install scrollbear

Usage

<div id='scroll' style='overflow: scroll;'>     <div id='container'>         <p>long content</p>         <p>long content</p>     </div> </div> <script src='scrollbear.js'></script>
Scrollbear.start(document.getElementById('scroll'))

API

Scrollbear.start(target [, changedItems])

target is the DOM where scroll bar exists (Normally is the container of contents), normally the direct child node of this target will be a DOM with really long content (such as the content of blog articles).

changeItems is optional. It is useful when images is lazy loading into your page. In such case, you can specify the placeholder of images. When images is lazy-loaded, the height of placeholder will change, and trigger the Scrollbear to justify the scroll position.

Development

npm install gulp

Contribute

Issues or PR are all Welcome!

License

MIT

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Scrollbear – A modern tool that maintains scroll position when images loaded

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮