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

awesome-slider

v1.2.0

Published

a vanilla javascript slider/carousel/swiper plugin

Downloads

36

Readme

awesome-slider npm version min minzip license

a vanilla javascript slider/carousel/swiper plugin.

Demo

Demo 合集 🚀

如果在框架中使用, 比如react, 需要在组件unmount时, 移除所有相关监听事件. 示例:

awesome-slider in react

installing

Using yarn

yarn add awesome-slider

Using npm

npm install awesome-slider

Using cdn

<script src="https://unpkg.com/awesome-slider/dist/awesome-slider.min.js"></script>

Example

const AwesomeSlider = require("awesome-slider");
// or
import AwesomeSlider from "awesome-slider";

const awesomeSlider = new AwesomeSlider(images, container, [options]);

API

images

  • Type : Array<String | Object>
  • Default: undefined
  • Usage

可以是简单模式

["./images/1.jpg", "./images/2.jpg", "./images/3.jpg", "./images/4.jpg"];

也可以自由组合

[
  {
    tagName: "a",
    attrs: {
      style: "",
      class: "",
      href: "https://wwww.example.com"
    },
    children: [
    "this just textNote, not object",
    {
      tagName: "div",
      attrs: {
      style:""
    },
  },
  "./images/example.jpg"
]

container

  • Type : Object
  • Default: undefined
  • Usage

包裹 images 的 html 元素

var container = document.querySelector(".container"); 👈

// react
...
const containerRef = useRef(null);
...
const container = containerRef.current; 👈
...
<div className="container" ref={containerRef}>

options

ratio

  • Type : Number
  • Default: 1180 / 500
  • Usage

宽高比

duration

  • Type : Number
  • Default: 1000 * 0.5
  • Usage

轮播动画过渡的时长(ms)

autoplay

  • Type : Boolean
  • Default: true
  • Usage

是否开启自动轮播

interval

  • Type : Number
  • Default: 1000 * 5
  • Usage

自动轮播的间隔时长(ms)

indicator

  • Type : {style: Function, active: Function}
  • Default: indicator
  • Usage

轮播状态的指示 js创建html, 通过有传递的参数做样式交互, 如果要使用this, 就不要使用箭头函数, 一般现有传递的参数够用

const style = ({ listWrap, realLen, initIndex }) => {};

const style = ({ current }) => {};

const indicator = {
  style,
  active
};

initIndex

  • Type : number
  • Default: 0
  • Usage

初始展示的图片的序号

manual

  • Type : {previous: Object, next: Object}
  • Default: null
  • Usage

js创建html, 插入两部分, 分别是previousnext

timing

  • Type : String | Function
  • Default: linear
  • Usage

轮播动画类型

enableResize

  • Type : Boolean
  • Default: false
  • Usage

是否开启窗口大小变化的监听

tip:如果container的大小是随窗口改变自适应的, 建议开启, 可以自动调整轮播图到正确位置

imageDownloading

  • Type : Object
  • Default: null
  • Usage

js创建html, 插入图片加载的效果

imagePlaceholder

  • Type : Object
  • Default: null
  • Usage

js创建html, 插入图片加载失败的占位

utils

内置的几个方法, 因为对自身不影响, 可以作为工具函数为外部所用

const AwesomeSlider = require("awesome-slider");
const { element, debounce, animate, translate } = AwesomeSlider.prototype.utils;

Note

使用了requestAnimationFrame, 如果要向低浏览器兼容, 可以自行引入requestAnimationFrame polyfill 比如yarn add raf