1.0.8 • Published 4 years ago

rax-xslider v1.0.8

Weekly downloads
92
License
-
Repository
github
Last release
4 years ago

npm

rax-xslider

描述

轮播增强,仅支持h5和weex

安装

$ npm install rax-xslider --save

API说明

属性都是非必填,所有属性h5和weex都支持

Slider

属性

属性类型默认值描述
loopBooleanfalse是否开启无缝轮播,安卓下无效
autoPlayBooleanfalse是否自动轮播
intervalNumber3000开启autoPlay后间隔时间,单位ms
resumeIntervalNumber2000手指离开后至开始autoPlay的间隔时间
durationNumber300切换的动画周期,单位ms
easingStringcubicBezier(.25,.1,.25,1)动画缓动函数
verticalBooleanfalse是否是纵向
cardSizeNumber750卡片宽度或者高度(vertical)
startGapNumber0卡片左(上)边边距
endGapNumber0卡片右(下)边边距
viewportSizeNumberundefined视窗宽度(高度)
extraBindingPropsArray[]根据slider滑动所需进行的额外的binding效果 如:[{element: this.refs.wrap,property: 'transform.translateX',expression:'x+0'}]
cardTransitionSpecObject{}卡片动画配置
beforeSwitchFunctionnoop切换到某个panel之前
afterSwitchFunctionnoop切换到某个panel之后
indicatorStyleObject导航器容器样式
indicatorItemStyleObject导航器选项样式
indicatorActiveItemStyleObject导航器当前选中项样式
indicatorComponentComponentIndicator自定义导航器组件,设置为null可以隐藏导航器
defaultIndexNumber0默认聚焦到第几个panel
minOffsetNumber滚动offset边界最小值(仅loop:false下生效)
maxOffsetNumber滚动offset边界最大值(仅loop:false下生效)
minLoadMoreOffsetNumberloadMore组件的onLoading触发最小距离

方法

名称参数返回值描述
switchTo(index, options){void}切换到某个tab
stopAutoPlay{void}停止自动播放
stopAnimate{void}停止动画

参数详解

index {Number} 索引

options

duration {Number}

动画周期,可覆盖全局duration

params

可携带自定义参数,在beforeSwitchafterSwitch中通过e.params获取

Slider.Panel

属性

名称类型默认值描述
onAppearFunctionnoop卡片处于可见区域时触发
onDisappearFunctionnoop卡片离开可见区域时触发

Slider.LoadMore

名称类型默认值描述
onLoadingFunctionnoop在边到达缘时触发(loop需要设置为false)

基本示例

// demo
/** @jsx createElement */
import {createElement, Component, render, createRef, useEffect} from 'rax';
import Text from 'rax-text';
import Slider from 'rax-xslider';

const styles = {
  item: {
    height: 400,
    backgroundColor: 'red',
    justifyContent: 'center',
    borderRadius: 24,
    borderWidth: 5,
    borderColor: '#000',
    borderStyle: 'solid'
  },
  txt: {
    color: '#fff',
    fontSize: 50,
    textAlign: 'center'
  },
  title: {
    backgroundColor: '#f7f7f7',
    color: '#444',
    textAlign: 'center',
    fontSize: 200,
    fontSize: 28,
    lineHeight: 80
  }
};

const colors = [
  'red',
  'green',
  'blue',
  'orange',
  'yellow'
];

export default function App() {
  const slider = createRef();
  const getCardTransitionSpec = () => {
    return {
      props: [
        {
          property: 'transform.scale',
          inputRange: [0, 1],
          outputRange: [0.8, 1]
        },
        {
          property: 'opacity',
          inputRange: [0, 1],
          outputRange: [.2, 1]
        }
      ]
    };
  }
  useEffect(() => {
    // use slider.current to get the instance
    slider.current.switchTo(3);
  }, []);
  return (
    <Slider
      ref={slider}
      loop={true}
      autoPlay={true}
      startGap={75}
      endGap={75}
      cardSize={600}
      cardTransitionSpec={getCardTransitionSpec}
    >
      {colors.map((color, i) => {
        return (<Slider.Panel style={{...styles.item, backgroundColor: color}} key={'panel' + i}>
          <Slider.PanView style={styles.panView}><Text style={styles.txt}>{i}</Text></Slider.PanView>
        </Slider.Panel>);
      })}
    </Slider>
  );
}

使用须知

  • 安卓下需要配合<Slider.PanView>或者<Slider.PanLink>使用,分别替代<View/><Link/>标签,否则可能无法滑动
  • 手势滑动可能会和外层的手势滑动冲突(比如scrollview嵌xslider纵向滑, slider嵌xslider横向滑,tab-panel嵌xsldier横向滑),请谨慎使用
1.0.8

4 years ago

1.0.8-0

4 years ago

1.0.8-1

4 years ago

1.0.7

4 years ago

1.0.7-2

4 years ago

1.0.7-1

4 years ago

1.1.0-beta.1

4 years ago

1.0.6

4 years ago

1.0.6-1

4 years ago

1.0.5

4 years ago

1.0.5-2

4 years ago

1.0.5-1

4 years ago

1.0.4

4 years ago

1.0.4-1

4 years ago

1.0.3

4 years ago

1.0.3-3

4 years ago

1.0.3-2

4 years ago

1.0.3-1

5 years ago

1.0.3-0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.5

6 years ago