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

@uiw/react-carousel

v4.22.3

Published

Carousel component

Downloads

733

Readme

Carousel 走马灯

Buy me a coffee Open in unpkg NPM Downloads npm version

滚动播放。在 v4.15.0+ 添加。

import { Carousel } from 'uiw';
// or
import Carousel from '@uiw/react-carousel';

基础用法

最简单的用法。

import React from 'react';
import { Carousel } from 'uiw';

export default function Demo() {
  return (
    <div style={{ display:'flex' }}>
      <Carousel>
        <div style={{ height: '100%', background: '#1EABCD' }}>
          <span>1</span>
        </div>
        <div style={{ height: '100%',  background: '#393b46' }}>
          <span>2</span>
        </div>
        <div style={{ height: '100%',  background: '#008EF0' }}>
          <span>3</span>
        </div>
        <div style={{ height: '100%',  background: '#393E48' }}>
          <span>4</span>
        </div>
      </Carousel>
      <span style={{marginLeft:10}}/>
      <Carousel direction="vertical" >
        <div style={{ height: '100%', background: '#1EABCD' }}>
          <span>1</span>
        </div>
        <div style={{ height: '100%',  background: '#393b46' }}>
          <span>2</span>
        </div>
        <div style={{ height: '100%',  background: '#008EF0' }}>
          <span>3</span>
        </div>
        <div style={{ height: '100%',  background: '#393E48' }}>
          <span>4</span>
        </div>
      </Carousel>
    </div>
  );
}

控制播放频率

palyTime设置每帧停留时间,scrollTime设置切换帧的速度

import React from 'react';
import { Carousel } from 'uiw';

export default function Demo() {
  return (
    <Carousel palyTime={1000} scrollTime={500}>
      <div style={{ height: '100%', background: '#1EABCD' }}>
        <span>1</span>
      </div>
      <div style={{ height: '100%',  background: '#393b46' }}>
        <span>2</span>
      </div>
      <div style={{ height: '100%',  background: '#008EF0' }}>
        <span>3</span>
      </div>
      <div style={{ height: '100%',  background: '#393E48' }}>
        <span>4</span>
      </div>
    </Carousel>
  );
}

切换到指定帧

手动切换到指定帧的位置

import React from 'react';
import { Carousel } from 'uiw';

export default function Demo() {

  const ref=React.useRef()
  const [autoPlay,autoPlaySet]=React.useState(true)

  return (
    <React.Fragment>
      <Carousel
        ref={ref}
        position={2}
        autoPlay={autoPlay}
        afterChange={(current)=>console.log('after',current)}
        beforeChange={(current)=>console.log('before',current)}
      >
        <div style={{ height: '100%', background: '#1EABCD' }}>
          <span>1</span>
        </div>
        <div style={{ height: '100%',  background: '#393b46' }}>
          <span>2</span>
        </div>
        <div style={{ height: '100%',  background: '#008EF0' }}>
          <span>3</span>
        </div>
        <div style={{ height: '100%',  background: '#393E48' }}>
          <span>4</span>
        </div>
      </Carousel>
      <button onClick={() => ref.current.gotoSlide(1)}>跳转</button>
      <button onClick={() => ref.current.prevSlide()}>上一张</button>
      <button onClick={() => ref.current.nextSlide()}>下一张</button>
      <button onClick={() =>autoPlaySet(autoPlay?false:true)}>{autoPlay?'暂停':'开始'}</button>
    </React.Fragment>
  );
}

Props

API

| 参数 | 说明 | 类型 | 默认值 | |--------- |-------- |--------- |-------- | | width | 宽度 | number | 400 | | height | 高度 | number | 200 | | position | 设置初始帧位置 | number | 0 | | palyTime | 每帧停留时间(ms) | number | 2000 | | scrollTime | 滚动动画的速度(ms) | number | 200 | | autoPlay | 是否自动播放 | boolean | true | | afterChange | 切换面板前的回调 | (current) => void | - | | beforeChange | 切换面板后的回调 | (current) => void | - | | direction | 滚动方位horizontal横向,vertical竖向 | horizontal | vertical | horizontal |

ref

  // 跳转到指定帧
  gotoSlide: (slideNumber: number) => void;
  // 上一针
  prevSlide: () => void;
  // 下一帧
  nextSlide: () => void;
  // 暂停播放
  stopPlay: () => void;