react 手机端touch 图片轮播
来源:互联网 发布:专业的音频软件 编辑:程序博客网 时间:2024/04/29 21:47
import React, { Component, PropTypes } from 'react';const styles = require('./DoctorSchedulesCard.scss');let startX;export default class DoctorSchedulesCard extends Component { static propTypes = { doctorSchedules: PropTypes.array, } constructor(props) { super(props); this.state = { touchIndex: 0, // 当前未隐藏div索引值 }; } componentDidMount() { // this.props.loadScheduleByDoctorName(); } componentWillReceiveProps() { } touchStart(event) { startX = event.changedTouches[0].pageX; } // 因为无论move 还是start 都会触发end事件。所以判断方向就在end事件中 touchEnd(event, index) { event.preventDefault(); const endX = event.changedTouches[0].pageX; if (endX - startX > 20) { // alert('点击左'); this.clickLeft(index); } else if (startX - endX > 20) { // alert('点击右'); this.clickRight(index); } } clickLeft(indexParam) { const allItemCounts = 3; // 总共轮播个数 const index = indexParam || this.state.touchIndex; console.log(index); this.setState({ touchIndex: index === 0 ? allItemCounts : index - 1, }); } clickRight() { const allItemCounts = 3; // 总共轮播个数 const index = this.state.touchIndex; this.setState({ touchIndex: index === allItemCounts ? 0 : index + 1, }); } render() { const {touchIndex} = this.state; return ( <div className={'list ' + styles.doctorSchedulesCardPage}> <div onClick={() => this.clickLeft()}>left</div> <div onClick={() => this.clickRight()}>right</div> <ul> <li onTouchStart={this.touchStart.bind(this)} onTouchEnd={(event) => this.touchEnd(event, 0)} style={{display: touchIndex === 0 ? 'block' : 'none'}}>第0张</li> <li onTouchStart={this.touchStart.bind(this)} onTouchEnd={(event) => this.touchEnd(event, 1)} style={{display: touchIndex === 1 ? 'block' : 'none'}}>第1张</li> <li onTouchStart={this.touchStart.bind(this)} onTouchEnd={(event) => this.touchEnd(event, 2)} style={{display: touchIndex === 2 ? 'block' : 'none'}}>第2张</li> <li onTouchStart={this.touchStart.bind(this)} onTouchEnd={(event) => this.touchEnd(event, 3)} style={{display: touchIndex === 3 ? 'block' : 'none'}}>第3张</li> </ul> </div> ); }}
0 0
- react 手机端touch 图片轮播
- react 实现手机端首页无缝轮播
- React Native-图片轮播
- 手机触模的图片轮播
- 移动端touch轮播+transition动画
- react-native中图片轮播的使用
- 手机webApp触摸左右滑动切换轮播图片广告
- 移动端图片轮播?
- 手机端 touch 事件
- 移动端的图片轮播
- 图片轮播
- 腾讯图片轮播
- js图片轮播
- js图片轮播
- JavaScript 图片轮播
- js图片轮播
- jquery 图片轮播
- jquery图片轮播
- java IO流
- 调频原理
- 添加地形图
- H5 调用android原生相机代码分析
- Spring的简单Demo
- react 手机端touch 图片轮播
- SharePreference不能及时读取已写入的数据
- MySQL 5.7 Reference Manual Chapter 10 Language Structure 参考手册第十章语言结构内容总结
- Android中ListView的回弹效果
- OpenCV的所有模块介绍
- Java开发中的23种设计模式详解(转)
- CSS居中总结
- UTF-8编码
- ios boundingRectWithSize 方法使用