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

@json_web_component/infinitscrollpagination

v0.0.6

Published

一个国际化的web component库, 可无感切换语言; An internationalized web component library with senseless language switching.

Downloads

1

Readme

InfinitScrollPagination 无限滚动分页组件

English Documents

介绍

这个自定义 Web 组件可以在网页应用中实现流畅的滚动分页功能。它支持双向加载新条目,并提供清晰的加载状态指示。

配置

InfinitScrollPagination 组件可以通过以下属性进行配置:

  • reverse:如果为true, 会滚到顶部进行下一页; 如果为false, 会滚动到底部进行下一页。
  • loading:是否正在请求中。
  • height:容器的高度, 如果不设置高度可能导致功能错误, 或者外层是如果需要自动撑开请用弹性盒子给父级, 给当前盒子设置flex-grow: 1。
  • has-more:是否有更多的数据。
  • class:组件添加样式的 CSS 类名, 注: 在react中也是用class而不是className。
  • threshold:距离可视区域边缘(顶部或底部,取决于 reverse 属性)的距离,值为0-1, 具体请查阅 MDN

方法

InfinitScrollPagination 组件提供以下方法:

  • scrollToTop():滚动内容容器到顶部。
  • scrollToEnd():滚动内容容器到底部。

事件

  • load():当滚动位置达到设定的 threshold 时触发。负责获取新数据并追加到内容容器中。

使用示例

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <script type="module" src="https://unpkg.com/@json_web_component/infinitscrollpagination/dist/main.min.js"></script>
  <title>Title</title>
  <script type="module">
  </script>
  <style>
    .scroll-container {}
  </style>
</head>

<body>
  <infinit-scroll class="scroll-container" height="200px">
  </infinit-scroll>
  <script>
    const container = document.querySelector('.scroll-container');
    let loading = false;
    let hasMore = true;
    container.setAttribute('has-more', hasMore);
    container.setAttribute('loading', loading);
    container.addEventListener('load', getListData)
    function getListData(page) {
      loading = true;
      container.setAttribute('loading', loading);
      setTimeout(() => {
        loading = false;
        hasMore = false;
        container.setAttribute('has-more', hasMore);
        container.setAttribute('loading', loading);
        console.log(page, '获取到数据');
        for (let i = 0; i < 12; i++) {
          const item = document.createElement('div');
          const styles = {
            height: '80px',
            background: '#eee',
            marginBottom: '10px'
          }
          for (const key in styles) {
            if (Object.hasOwnProperty.call(styles, key)) {
              const val = styles[key];
              item.style[key] = val;
            }
          }
          // 如果 reverse 为 true
          container.append(item);
          // 如果 reverse 为 false
          // container.prepend(item)
          // 如果需要滚动到底部
          // container.scrollToEnd();
          // 如果需要滚动到顶部
          // container.scrollToTop();
        }
      }, 800)
    }
  </script>
</body>

</html>
<!-- 原生 html 引用 -->
<script type="module" src="https://unpkg.com/@json_web_component/infinitscrollpagination/dist/main.min.js"></script>
// vue3 vite处理
export default defineConfig({
    plugins: [
        vue({
            template: {
                compilerOptions: {
                isCustomElement: tag => tag === 'infinit-scroll'
                }
            }
        })
    ]
})
// vue 或 react只需在 main.js 中引用
import "@json_web_component/infinitscrollpagination";
// 其他使用方法请参考html的写法结合 vue 的写法
// tsconfig 中添加 include
{
  "compilerOptions":{},
  "include": ["node_modules/@json_web_component/infinitscrollpagination/dist/global.d.ts"],
}
// react 使用问题
// 如果ts报错: Property 'infinit-scroll' does not exist on type 'JSX.IntrinsicElements'.
// 1. 创建一个全局类型文件 例如 global.d.ts
// 2. 在tsconfig 中include 中加入该全局类型文件
// 该全局文件的内容如下:

declare namespace JSX {
  interface IntrinsicElements {
    'infinit-scroll': React.DetailedHTMLProps<InfinitScrollPaginationAttr, HTMLElement>;
  }
}

// 如果需要在定义当前元素的ref类型
// vue
const cusref = ref<InfinitScrollPaginationElement | null>(null);
// react
const cusref = useRef<InfinitScrollPaginationElement | null>(null)