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

@ifun-vue2/seamless-scroll

v1.2.2

Published

数据无缝滚动,数据量大时,开启虚拟滚动,提升页面性能.

Downloads

5

Readme

安装

npm i @ifun-vue2/seamless-scroll

使用

import IFunSeamlessScroll from "@ifun-vue2/seamless-scroll";
// 样式
import "@ifun-vue2/seamless-scroll/dist/style.css";
// 使用
Vue.use(IFunSeamlessScroll);

特点

  • 实现数据的无缝滚动(纵向)
  • 实现大数据量的虚拟无缝 滚动(大数据量优化)
  • 滚动内容自定义渲染
  • 滚动区域内,滚动可由鼠标控制滚动

基本使用,数据滚动

通过传入data, 数据类型为数组。

<template>
  <div style="margin-bottom:20px;height:300px;">
    <IFunSeamlessScroll :data="data" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [],
    };
  },
  mounted() {
    this.data = new Array(100).fill(0).map((item, index) => ({
      value: index,
      label: "数据" + index,
    }));
  },
};
</script>

自定义数据渲染 key

使用options 来定义数据下拉渲染定义的 value、label 值。还有pageSizeitemWidth

<template>
  <div style="margin-bottom:20px;">
    <IFunSeamlessScroll :data="data" :options="options" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [],
      options: {
        value: "id",
        label: "title",
      },
    };
  },
  mounted() {
    this.data = new Array(100).fill(0).map((item, index) => ({
      id: index,
      title: "数据" + index,
    }));
  },
};
</script>

开启虚拟滚动列表

通过传入virtual:true, 标识开启虚拟列表。还需要确认传入参数options.pageSize 默认100,也就是低于 100 会全部渲染。数据量不大开启虚拟滚动也没啥作用。性能比不上全部渲染滚动。

<template>
  <div style="margin-bottom:20px;height:300px;">
    <IFunSeamlessScroll :data="data" :virtual="true" :options="options" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [],
      options: {
        // 定义size
        pageSize: 20,
      },
    };
  },
  mounted() {
    this.data = new Array(100).fill(0).map((item, index) => ({
      value: index,
      label: "数据" + index,
    }));
  },
};
</script>

定义滚动速度

通过属性speed 定义滚动速度。数值越大就越快。默认1

<template>
  <div style="margin-bottom:20px;height:300px;">
    <IFunSeamlessScroll :data="data" :speed="2" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [],
    };
  },
  mounted() {
    this.data = new Array(100).fill(0).map((item, index) => ({
      value: index,
      label: "数据" + index,
    }));
  },
};
</script>

scroll关闭滚动

通过传入scroll:false, 标识不需要滚动。这种场景在于数据量少于滚动区域时,滚动反而没有任何意义。

此时可以通过定义 :scroll="data.length>5" 展示所有的数据。这完全取决于你的主观判断;

当然你也可以在数据量多是关闭自动滚动,此时你可以设置跟元素overflow:auto 手动滚动。

<template>
  <div style="margin-bottom:20px;height:300px;">
    <IFunSeamlessScroll
      :data="data"
      :scroll="data.length > 5"
      :options="options"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [],
      options: {
        // 定义size
        pageSize: 20,
      },
    };
  },
  mounted() {
    this.data = new Array(100).fill(0).map((item, index) => ({
      value: index,
      label: "数据" + index,
    }));
  },
};
</script>

slot

  • 提供两个 slot 定义内容区域。没有数据时,为空时,可通过empty slot 定义数据空展示状态。

  • 自定义元素渲染 slot 具名item。即可进行自定义数据渲染。

<template>
  <div style="margin-bottom:20px;height:300px;">
    <IFunSeamlessScroll
      :data="data"
      :scroll="data.length > 5"
      :options="options"
    >
      <template v-slot="{ params }">
        <div class="info">
          <span>{{ params.label }}</span>
          <span>{{ params.value }}</span>
        </div>
      </template>
    </IFunSeamlessScroll>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [],
      options: {
        // 定义size
        pageSize: 20,
      },
    };
  },
  mounted() {
    this.data = new Array(100).fill(0).map((item, index) => ({
      value: index,
      label: "数据" + index,
    }));
  },
};
</script>

重要 为了最佳的滚动效果查看,请定义options.itemWidth ;

动态计算滚动高度,这样可以无差别切换渲染。默认itemWidth:30 如果各个元素高度不一,则滚动效果不好。

鼠标滚动控制内容滚动

滚动内容区放开了鼠标滚动;可对当前内容实现鼠标的滚轮滚动;

不开启虚拟滚动时,没有任何问题;

开启虚拟滚动,当向上滚动时,分批次数据仅滚动到内容区顶部,不会在进行循环渲染;向下滚动则没有问题;

API 属性一览

| props | 说明 | 默认值 | | ----------- | -------------------- | ---------------- | | virtual | 是否开启虚拟滚动 | 默认 false | | data | 数据源 | 必传,Array | | speed | 滚动速度 | 默认 1 | | options | 滚动配置 | 详见下表 Options | | scroll | 控制是否需要自动滚动 | 默认 true | | whellScroll | 鼠标滚轮支持滚动 | 默认 true |

ScrollOptions

| props | 说明 | 默认值 | | --------- | :----------------: | ----------------------------------------------------------- | | value | 数据 key 值 | 默认 value | | label | 数据展示的名称 | 默认 label | | pageSize | 列表渲染的数据量 | 默认 100 | | itemWidth | 渲染的数据元素高度 | 竖向滚动为高度,横向滚动为宽度(暂时没有横向滚动),默认 30 |