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

p-seamless-scroll

v0.7.0

Published

p-seamless-scroll

Downloads

71

Readme

p-seamless-scroll 官方文档

GitHub license GitHub stars GitHub forks NPM Version npm bundle size

p-seamless-scroll 是一个创建无缝滚动效果的 js 插件。它有着轻量且高效的特性,支持丰富的自定义配置选项,提供了一系列 API 方法以及事件监听功能。

配置

  • el: 滚动容器的 DOM 元素。
  • direction: 滚动方向,可选值包括 'up' (默认) 、 'down' 、 'left' 、 'right'。
  • speed: 滚动速度,以毫秒为单位,默认为 100。
  • hoverStop: 是否在鼠标移入时停止滚动,默认为 false。
  • auto: 是否自动开始滚动,默认为 true。
  • loop: 是否循环滚动,默认为 true。
  • rest: 在滚动一段距离后停留一段时间,默认为 null,例如{distance: 100, time: 2000}。
    • distance: 停留前滚动的距离,以 px 为单位,必须为 10 的整数倍,默认为 100。
    • time: 停留的时间,以毫秒为单位,默认为 2000。

属性

  • state: 对象的状态信息,包含以下属性:
    • isHover: 是否鼠标移入滚动容器。
    • isPause: 是否暂停滚动。

方法

  • init(e): 初始化。实例化 new pSeamlessScroll()之后自动初始,无需调用此方法。此方法用作 destroy()之后再次使用时调用。
  • play(): 开始滚动。如果配置自动开始滚动则初始化后无需调用此方法。
  • pause(): 暂停滚动。
  • reload(e): 重载配置。接受一个配置对象 e,并更新当前实例的配置。
  • destroy(): 销毁滚动实例,清除定时器并释放资源。
  • getState(): 获取当前状态对象。

事件

  • on(event, callback): 监听事件。event 可以是以下值:

    • hover: 鼠标移入或移出滚动容器时触发。
    • pause: 滚动暂停或继续时触发。
  • off(event): 移除事件监听。event 可以是以下值:

    • hover
    • pause

安装引入

npm 安装

npm install p-seamless-scroll --save

esm 引入

import pSeamlessScroll from "p-seamless-scroll";

cdn 引入

<script src="https://unpkg.com/p-seamless-scroll@[version]/lib/p-seamless-scroll.umd.js"></script>

使用示例

<style>
  .fbox {
    width: 160px;
    height: 160px;
    border: 1px solid #ccc;
  }
  .sbox {
    width: 240px;
    height: 240px;
    background-image: url(https://pbstar.github.io/p-seamless-scroll/logo.png);
  }
</style>

<div class="fbox" id="scrollContainer">
  <div class="sbox"></div>
</div>
// 假设已经有一个滚动容器的 DOM 元素,ID 为 'scroll-container'
const scrollContainer = document.getElementById("scroll-container");

// 实例化 pSeamlessScroll
const pss = new pSeamlessScroll({
  el: scrollContainer,
});