当前位置: 首页 > news >正文

展示营销类网站江西省农村公路建设举报网站

展示营销类网站,江西省农村公路建设举报网站,离退休干部网站建设,旅行做攻略的网站好本文是react通过react-swipeable-views创建公共轮播图组件的续文 上一文 我们创建了这样的一个轮播图组件 但我们已经看到的轮播图 下面都会有小点 展示当前所在的位置 但react-swipeable-views 并没有直接提供 我们需要自己去编写这个组件 我们在components下的 rotationCh…

本文是react通过react-swipeable-views创建公共轮播图组件的续文

上一文 我们创建了这样的一个轮播图组件
在这里插入图片描述
但我们已经看到的轮播图 下面都会有小点 展示当前所在的位置
但react-swipeable-views 并没有直接提供 我们需要自己去编写这个组件

我们在components下的 rotationChart 创建一个 Pagination.jsx 组件

然后 在同目录下创建一个样式文件 我这里叫 Pagination.css
参考代码如下

.swiper-pagination{position: absolute;bottom: 10px;right: 10px;display: inline-block;height: auto;width: 100%;
}
ul {width: 100%;height: auto;text-align: center;
}
li {list-style: none;display: inline-block;height: 10px;width: 10px;border-radius: 50%;background-color:#ccc;margin: 0 3px;
}
li.selected {background-color:rgb(233,32,61);
}

Pagination.jsx 参开代码如下

import React from 'react';import './Pagination.css';export default class Pagination extends React.Component{render(){const quantity = this.props&&this.props.quantity?new Array(this.props.quantity).fill(1):[];const currentIndex = this.props&&this.props.currentIndex?this.props.currentIndex:0;return (<div className = "swiper-pagination"><ul>{quantity.map((element,index) => {return <liclassName = { currentIndex === index?'selected':'' }key = { index }></li>})}</ul></div>)}
}

这里 我们又多接收了一个参数 叫 currentIndex 判断 如果 currentIndex 和 当前下班的index相同 则给与选中状态

那么 我们来到 components/rotationChart下的index.jsx 更改代码如下

import React from 'react';
import SwipeableViews from 'react-swipeable-views';
import Pagination from './Pagination';import './index.css';export default class Swiper extends React.Component{constructor(props){super(props);this.state = {currentIndex: 0}}handleChangeIndex = (index) => {this.setState({currentIndex: index})}render(){const banners = this.props&&this.props.banners?this.props.banners:[];const height = this.props&&this.props.height?this.props.height:"200px";const width = this.props&&this.props.width?this.props.width:"400px";return (<div className = "swiper" style = { {height,width} }><SwipeableViews onChangeIndex={ this.handleChangeIndex }>{banners.map((element ,index) => {return (<div className='swiper-view' key= { index }><img src={ element } alt=""/></div>)})}</SwipeableViews><Pagination currentIndex = { this.state.currentIndex } quantity = { banners.length }/></div>)}
}

这里我们用了 react-swipeable-views组件中的 onChangeIndex函数 监听了切换事件 返回一个参数

就是当前轮播图所在的下标 然后给到 Pagination组件 运行结果如下
在这里插入图片描述
在这里插入图片描述
此时 我们下方的三个小点就实现了 因为这个组件是自己写的 如果想改样式 直接在 Pagination.css中改就好了

http://www.yayakq.cn/news/56139/

相关文章:

  • 网站后台管理需求wordpress自适应幻灯片
  • 网站建设典型发言网站背景图片切换
  • 做头像网站静态北京网站建设 和君
  • 住房城乡与建设厅网站南宁网站建设公司seo优化
  • 网站导航条和表格怎么做wordpress淘宝客pid
  • 学做软件和网站需要知识商业网站改版需要多久
  • 高端网站建设联系方式摄影网站的规划与设计
  • 高端网站设计培训机构可以做企业网站
  • 让人家做网站需要问什么问题重庆网站排名优化
  • 廊坊建设局网站网站怎么做自然优化
  • 长城宽带做网站呼和浩特住房和城乡建设部网站
  • 做网站开票是多少个点的票网站域名申请费用
  • 布拖网站建设哈尔版网站建设
  • 手机网站 微信分享网站建设crm
  • 做网站软件有哪些桂林生活网招聘信息网
  • 网站建设网站建设哪里有公司怎么开网站
  • 做网站项目时 需求分析的内容厦门建网站做优化
  • 肃宁县网站建设价格咨询服务类网站建设
  • 百度网站前三名权重一般在多少网站建设意见
  • 河南省建设注册执业中心网站外国客户网站
  • 网站建设费用有哪些方面做网页的软件做网站
  • 电脑网站加速器168推广网
  • 学校网站建设有什么平台可以免费发布推广信息
  • 网站建设基础考试怎么使用微wordpress
  • asp网站水印支除天津市建设教育培训中心网站
  • 娄底网站建设设计360客户如何做网站推广
  • 长沙网站建设市场低价关于网站建设的问卷分析
  • 做网站合肥哪家公司好wordpress 论坛主题
  • 正规的网站建设官网网站建设人员职责
  • 描述网站的含义专业自动化网站建设