npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

better-scroller

v1.0.0

Published

high performance scroller

Downloads

5

Readme

移动端高性能滚动组件

基于infinite-scroller改进、封装

当页面元素过多时,内存占用会持续增加,页面重绘的时候占用的CPU资源也会随之增大,页面频繁滚动或者重排的时候就会出现明显的卡顿。 此组件可以有效解决海量数据列表动态加载时的性能问题,可以在性能较差的设备上流畅地滚动,帧率能接近理想化的60FPS(同等条件下iScroll的无限加载版本只能达到30FPS左右)。 可以动态加载任何形式的UI节点,不要求节点具有相同的结构或者尺寸,可以随意定制每个节点的UI。demo

实用场景

  • 需要大规模动态加载数据的
  • 想要通过墓碑元素改善加载视图
  • 不需要兼容IE9-的应用

实现原理

  • 通过will-change: transform;开启元素3D加速(目前chrome、safari、firefox支持)
  • 通过contain: layout;开启元素的(目前仅chrome支持)
  • 通过节点的复用,维持页面的节点数量在一个设定的范围,降低内存占用,减少页面重绘、重排的性能开销
  • 通过墓碑节点实现更友好的数据加载站位显示
  • 数据更新导致滚动位置变化的时候通过记录锚点元素实现滚动定位

改进

  • 去除第三方依赖(摘除es6-promise.js依赖,减少代码量,降低接入成本,也有利于后期兼容更低版本浏览器)
  • 解决原生Promise性能问题(提升2~3倍,详情
  • resize事件做防抖操作,对scroll事件做节流操作
  • 多种接入方式的支持(支持全局、ES6模块、AMD、CMD方式接入)

使用

  • npm包引用
  # 安装模块
  # @sea https://www.npmjs.com/package/better-scroller
  npm i -S better-scroller
  // ES6 使用方式
  import BetterScroller from 'better-scroller';
  
  // cmd 使用方式
  // let BetterScroller = require('better-scroller');
  • 全局引用
  <script src="//j1.58cdn.com.cn/git/scroller/index.min.js"></script>
  • 模块加载器引用
  // cmd 使用方式(如seajs)
  let BetterScroller = require('dist/index.min.js');

  // amd 使用方式(如requirejs)
  requirejs(['dist/index.min.js'], function(BetterScroller) {
    // TODO
  });
  • 调用
<div id="templates">
  <li class="item" data-id="{{id}}">
    <img class="avatar" width="48" height="48">
    <div class="bubble">
      <p></p>
      <img width="300" height="300">
      <div class="meta">
        <time class="posted-date"></time>
      </div>
    </div>
  </li>
  
  <li class="item tombstone" data-id="{{id}}">
    <img class="avatar" width="48" height="48" src="images/unknown.jpg">
    <div class="bubble">
      <p></p>
      <p></p>
      <p></p>
      <div class="meta">
        <time class="posted-date"></time>
      </div>
    </div>
  </li>
</div>
<ul id="scroll-container"></ul>
  #templates {display: none}
  
  #scroll-container {
    position: absolute;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: scroll;
    box-sizing: border-box;
    
    /*safari上开启原生滚动*/
    -webkit-overflow-scrolling: touch;
    /*chrome重隔离优化*/
    contain: layout;
    /*开启3D加速*/
    will-change: transform;
  }
  
  .item {
    display: flex;
    padding: 10px 0;
    width: 100%;
    contain: layout;
    will-change: transform;
  }
  let scroller = new BetterScroller(
    document.querySelector('#scroll-container'),
    new ContentSource())

TODO

  • 源码中TODO的问题
  • issue中一些问题
  • 上拉加载数据
  • IE8-兼容性问题