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

wil-carousel-img

v1.0.0

Published

图片轮播组件

Downloads

1

Readme

wil-carousel-img

一套基于dom节点的图片轮播组件

Demo示例
前往Gitee

注意

  1. 图片轮播组件在修改轮播图片列表之后,调用 carousel.init(dom); 方法即可更新轮播图片列表。

安装

npm install wil-carousel-img

使用方式

<style>
  .carousel-wrap {
    /* 图片轮播组件容器,这两个CSS属性必须存在 */
    position: relative;
    overflow: hidden;
  }
</style>
<div class="carousel-wrap">
  <div class="img-box">
    <div class="carousel-slider">
      <img class="carousel-img" src="http://img0.imgtn.bdimg.com/it/u=2125288902,1890865968&fm=26&gp=0.jpg">
    </div>
    <div class="carousel-slider">
      <img class="carousel-img" src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2520433466,1070276963&fm=26&gp=0.jpg">
    </div>  
    <div class="carousel-slider">  
      <img class="carousel-img" src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2520433466,1070276963&fm=26&gp=0.jpg">
    </div>  
    <div class="carousel-slider">  
      <img class="carousel-img" src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2520433466,1070276963&fm=26&gp=0.jpg">
    </div>  
    <div class="carousel-slider">  
      <img class="carousel-img" src="http://img2.imgtn.bdimg.com/it/u=415472049,3360294245&fm=26&gp=0.jpg">
    </div>  
  </div>
  <ul class="indicator-list"></ul>
</div>
import Carousel from 'wil-carousel-img';

var dom = document.getElementsByClassName('carousel-wrap')[0];
var carousel = new Carousel();
carousel.init(dom);

在 Vue 中使用

<template>
  <div class="app-wrap">
    <div class="carousel-wrap" ref="carouselWrap">
      <div class="img-box">
        <div class="carousel-slider" v-for="(item, index) in imgList" :key="index">
          <img class="carousel-img" :src="item">
        </div>
      </div>
      <ul class="indicator-list"></ul>
    </div>
    <button v-tap="addImg">添加图片</button>
  </div>
</template>
<script>
import Carousel from 'wil-carousel-img';
export default {
  name: 'Demo',
  data () {
    return {
      carousel: null,
      imgList: [
        'http://img0.imgtn.bdimg.com/it/u=2125288902,1890865968&fm=26&gp=0.jpg',
        'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2520433466,1070276963&fm=26&gp=0.jpg',
        'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2520433466,1070276963&fm=26&gp=0.jpg',
        'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2520433466,1070276963&fm=26&gp=0.jpg'
      ]
    }
  },
  methods: {
    addImg () {
      this.imgList.push('http://img0.imgtn.bdimg.com/it/u=2125288902,1890865968&fm=26&gp=0.jpg');
      this.$nextTick(() => {
        this.carousel.init(this.$refs.carouselWrap);
      });
    }
  },
  mounted () {
    this.carousel = new Carousel();
    this.carousel.init(this.$refs.carouselWrap);
  }
}
</script>
<style>
  .carousel-wrap {
    position: relative;
    overflow: hidden;
  }
</style>

API

new Carousel(Object object)

用于初始化一个Carousel实例,返回初始化后的Carousel实例。

参数 Object object

属性 | 类型 | 默认值 | 是否必填 | 说明
-|-|-|-|-| autoPlay | Boolean | true | 否 | 是否开启自动轮播 delay | Number | 3500 | 否 | 轮播图轮播间隔时间 width | Number | 无 | 否 | 图片轮播组件容器宽度 showIndicator | Boolean | true | 否 | 是否展示轮播图指示器 sliderChange | Function | 无 | 否 | 轮播图切换触发执行的回调函数,返回当前轮播图的索引值

carousel.init(dom)

初始化Carousel

参数 | 类型 | 默认值 | 是否必填 | 说明
-|-|-|-|-| dom | Object | 无 | 是 | 图片轮播组件容器DOM节点

carousel.slideTo(index)

滑动到指定轮播图索引位置

参数 | 类型 | 默认值 | 是否必填 | 说明
-|-|-|-|-| index | Number | 无 | 是 | 轮播图索引从0开始。当开启自动轮播的情况下,暂不进行支持 slideTo 方法