赞
踩
效果图
思路
jsx
import React, { Component } from 'react' import './cardCarousel.less' export default class CardCarousel extends Component { constructor(props){ super(props) this.state = { list:[1,2,3,4,5,6], current: 1, // 轮播图当前 index itemWidth:0, // 图片区域 宽度 out: 3, // 堆叠式 外部看到的数量 (左右各相同) 不限制 可以设置 0 或 大于轮播图数量 offset:80, // 堆叠式 外部偏移量 (产生堆叠效果) } } componentDidMount(){ // 获取轮播图片区域宽度 const width = this.refs.swiperitem.clientWidth this.setState({ itemWidth:width }) } // 上一张 onPrev = (index) => { const length = this.state.list.length if( index - 1 < 0) { this.setState({ current : length -1 }) }else { this.setState({ current : index -1 }) } } // 下一张 onNext = (index) => { const length = this.state.list.length if ( index + 1 === length) { this.setState({ current: 0 }) }else{ this.setState({ current: index + 1 }) } } render() { let {list,current,itemWidth,out,offset} = this.state // 水平式 计算轮播区整体位移 let x = current === 0 ? 0 : - current*itemWidth
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。