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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@eyeear/mscroll

v1.1.0

Published

模拟滚动(条)

Downloads

19

Readme

MScroll

模拟滚动(条),支持水平、垂直方向选择,滚动条显示,图片懒加载,鼠标拖动、滚动,选择器模式。

安装

npm install @eyeear/mscroll --save

使用

import MScroll from '@eyeear/mscroll'

OR

<script src="lib/mscroll.js"></script>
  <div class="wrapper">
      <div class="scroller">
          <div class="item">...</div>
          <div class="item"><img src="placeholder.png" data-src="1.jpg" /></div>
          ...
      </div>
  </div>
  // 水平方向 不显示滚动条
  new MScroll('.wrapper')

  // 垂直方向 显示滚动条
  new MScroll('.wrapper', {
    vertical: true,
    showScrollbar: true
  })

  // 图片懒加载
  new MScroll('.wrapper', {
    lazyload: true
  })

  // 鼠标拖动、滚动
  new MScroll('.wrapper', {
    mouse: true,
    wheel: true
  })

  // 选择器模式 垂直方向
  new MScroll('.wrapper', {
    vertical: true,
    picker: true
  })

  // 到底加载更多 垂直方向
  new MScroll('.wrapper', {
    vertical: true,
    scrollEnd: (offset, maxOffset) => {
      if (offset == maxOffset) {
        // 加载更多
        // ...
      }
    }
  })
  // 或者
  const scroll = new MScroll('.wrapper', {
    vertical: true
  })
  scroll.$on('scrollEnd', (offset, maxOffset) => {
    if (offset == maxOffset) {
      // 加载更多
      // ...
    }
  })

  ...
  

选项

  new MScroll(el, options)

  el 
    - 必须设置 外围包裹元素 一个css选择器或者元素对象
  
  options
    -选项属性
    - vertical 是否垂直方向 默认false 
    - showScrollbar 是否显示滚动条 默认false
      - scrollbarColor 滚动条颜色 默认 '#000' 
      - scrollbarSize 滚动条大小 默认 3 (px) 
      - scrollbarOpacity 滚动条透明度 默认 0.5 (0 - 1) 
    - lazyload 是否图片懒加载 默认false
      - attribute 放置图片地址的特性 默认 data-src  
    - mouse 是否使用鼠标拖动 默认false 
    - wheel 是否使用鼠标滚动 默认false
      -wheelStep 滚动动画步长 40 (px)
      -wheelTime 滚动动画持续时间 默认 400 (ms)
    - picker 是否使用选择器模式 默认false 
      - index 默认选择第几项 默认0第一项
    - scrollTime 手指、鼠标触发滚动动画的持续时间 默认 600 (ms)
    - rollTime 手指、鼠标触发复位动画的持续时间 默认 300 (ms)
    
    -选项方法
    - setup 第一次设置完成、浏览器resize 执行回调
    - scrollStart 滚动开始执行回调
    - scrollMove 滚动中执行回调
    - scrollEnd 滚动结束执行回调

  instance 实例方法
    - refresh() scroller滚动容器尺寸发生变化时 手动刷新
    - scrollTo(offset, duration) scroller滚动到指定位置 
    - moveTo(el, duration, center) scroller滚动到内部元素所在位置 center为true则元素位于中间位置
    - pickTo(index, duration) 选择器模式时 选择指定的元素
    - destroy() 要销毁实例时调用 注销事件绑定