Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rax-slider

Package Overview
Dependencies
Maintainers
2
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rax-slider

Slider component for Rax.

  • 3.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
73
decreased by-34.23%
Maintainers
2
Weekly downloads
 
Created
Source

rax-slider

npm

Web 场景推荐使用 rax-swiper

rax-slider 由于历史原因,可能存在一些问题,非内联样式场景强烈推荐使用 rax-swiper

支持

Web / Weex / 阿里小程序 / 微信小程序 / 字节跳动小程序

描述

轮播组件,就是以幻灯片的方式,在页面中横向展示诸多内容的组件。 轮播内容相互独立,前后在内容以及数据上都不存在逻辑关系。

安装

$ npm install rax-slider --save

属性

  1. Web 环境中 slider 内部默认做了节点的懒加载渲染,不再需要使用 picture 的lazyload做懒加载
  2. paginationStyleitemColor 用来定义分页原点的颜色,itemSelectedColor 用来定义分页原点激活时的颜色,itemSize用来定义分页圆点的大小,小程序只支持设置 itemColor 用来定义分页原点的颜色,itemSelectedColor。快应用只支持itemColoritemSelectedColoritemSize三个用来定义分页圆点的样式。默认样式如下:
{
  position: 'absolute',
  width: '40rpx',
  height: '40rpx',
  bottom: '20rem',
  left: 0,
  itemColor: 'rgba(255, 255, 255, 0.5)',
  itemSelectedColor: 'rgb(255, 80, 0)',
  itemSize: '8rpx'
}
属性类型默认值必填描述支持
widthstring-Slider 的宽度browser weex miniApp wechatMiniprogrambytedanceMicroAppquickApp
heightstring-Slider 的高度browser weex miniApp wechatMiniprogrambytedanceMicroAppquickApp
autoPlaybooleanfalse是否自动播放browser weex miniApp wechatMiniprogrambytedanceMicroAppquickApp
showsPaginationbooleantrue是否显示指示点browser weex miniApp wechatMiniprogrambytedanceMicroApp
paginationStyleobject-自己定义指示点的样式,否则默认样式居中browser weex miniApp wechatMiniprogrambytedanceMicroApp
loopbooleantrue是否是循环播放browser weex miniApp wechatMiniprogrambytedanceMicroApp quickApp
indexnumber0指定默认初始化第几页browser weex miniApp wechatMiniprogrambytedanceMicroApp
autoPlayIntervalnumber3000自动播放的间隔时间browser weex miniApp wechatMiniprogrambytedanceMicroApp
onChangefunction-index 改变时会触发browser weex miniApp wechatMiniprogrambytedanceMicroApp quickApp
directionstringhorizontalSlider 滚动方向 (horizontal / vertical)miniApp wechatMiniprogrambytedanceMicroApp quickApp

方法

Slider.slideTo(index: number)

参数
属性类型默认值必填描述
indexnumber-滚动到指定索引的 View

Slider.Item

每一个需要被轮播的子元素需要被包裹在 Slider.Item 组件中,在 Weex 和 Web 该组件是 Fragment 空节点,在小程序该组件是 swiper-item。由于该节点没有实际意义,所以不要在该组件上设置样式和绑定事件。 如果只在 Web 和 Weex 中使用,每一个需要轮播的子项无需包裹 Slider.Item 组件。

示例

import { createElement, Component, render, createRef } from 'rax';
import View from 'rax-view';
import Image from 'rax-image';
import Slider from 'rax-slider';
import DriverUniversal from 'driver-universal';

class App extends Component {
  constructor(props) {
    super(props);

    this.inputRef = createRef();
  }

  onchange = (index) => {
    console.log('change', index);
  };

  onClick = () => {
    this.inputRef.current.slideTo(0);
  };

  render() {
    return (
      <View>
        <Slider
          className="slider"
          width="750"
          height="500"
          style={styles.slider}
          autoPlay={true}
          loop={true}
          showsPagination={true}
          paginationStyle={styles.paginationStyle}
          autoplayTimeout={3000}
          onChange={this.onchange}
          ref={this.inputRef}
        >
          <Slider.Item>
            <View style={styles.itemWrap}>
              <Image
                style={styles.image}
                source={{
                  height: 500,
                  width: 375,
                  uri: '//gw.alicdn.com/tfs/TB19NbqKFXXXXXLXVXXXXXXXXXX-750-500.png',
                }}
              />
            </View>
          </Slider.Item>
          <Slider.Item>
            <View style={styles.itemWrap}>
              <Image
                style={styles.image}
                source={{
                  height: 500,
                  width: 375,
                  uri: '//gw.alicdn.com/tfs/TB1tWYBKFXXXXatXpXXXXXXXXXX-750-500.png',
                }}
              />
            </View>
          </Slider.Item>
          <Slider.Item>
            <View style={styles.itemWrap}>
              <Image
                style={styles.image}
                source={{
                  height: 500,
                  width: 375,
                  uri: '//gw.alicdn.com/tfs/TB1SX_vKFXXXXbyXFXXXXXXXXXX-750-500.png',
                }}
              />
            </View>
          </Slider.Item>
        </Slider>

        <View onClick={this.onClick}>Click</View>
      </View>
    );
  }
}

const styles = {
  slider: {
    width: 750,
    position: 'relative',
    overflow: 'hidden',
    height: 500,
    backgroundColor: '#cccccc',
  },
  itemWrap: {
    width: 750,
    height: 500,
  },
  image: {
    width: 750,
    height: 500,
  },
  button: {
    marginTop: 20,
    width: 340,
    height: 80,
  },
  paginationStyle: {
    position: 'absolute',
    width: 750,
    height: 40,
    bottom: 20,
    left: 0,
    itemColor: 'rgba(255, 255, 255, 0.5)',
    itemSelectedColor: 'rgb(255, 80, 0)',
    itemSize: 16,
  },
};

render(<App />, document.body, { driver: DriverUniversal });

Keywords

FAQs

Package last updated on 20 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc