0.1.3 • Published 6 months ago

scrollv v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

scrollv

一个基于 Web Component 的虚拟滚动库

🌰:包含 1000 个随机高度项的虚拟列表

<head>
  <script src="./dist/scrollv.umd.js"></script>
  <script>Scrollv.define('scroll-v', Scrollv.AutoHeight)</script>
</head>
<body>
  <button id="btn">滚动</button>
  <!-- 
   1. style      容器宽高由外部决定
   2. total      代表渲染列表总条目数
   3. itemHeight 预期的高度
   4. pad?:      在屏幕外缓存区域
   5. passive?:  不需要执行 preventDefault 时开启可以优化滚动效果
   6. rate?:     滚动倍率
   -->
  <scroll-v 
    style="height: 60vh; width: 300px;" 
    total="1000" 
    itemHeight="150" 
    pad="300"
    passive="true"
    rate="1"
  />
</body>
<script>
  // mock 1000 random height data
  const data = Array.from({ length: 1000 }, (_, i) => ({
    height: 150 + Math.random() * 200,
    i,
  }));

  // slice 事件触发时重新渲染可视区域
  scrollv.addEventListener('slice', (e) => {
    const { start, end } = e.detail;
    scrollv.innerHTML = data.slice(start, end).map((item) =>
      `<div style="height: ${item.height}px; border: 1px solid black;">
        ${item.i}
     </div>`
    ).join('');
  });

  // 使用 delta 滚动方式, 向下滚动 1000px
  btn.addEventListener('click', () => {
    scrollv.scrollv('delta', { dt: 1000 })
  })
</script>
0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

7 months ago

0.0.14

7 months ago

0.0.13

7 months ago

0.0.12

7 months ago

0.0.11

7 months ago

0.0.10

7 months ago

0.0.9

8 months ago

0.0.8

8 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago