I'm trying to create a swipe event using React. I do not want to use any external component or jquery.
The css is something like :
.outter{
position:relative;
width: 100%;
height: 150px;
background-color: blue;
}
.inner{
position: absolute;
width: 1000%;
left: 50px;
}
.child{
float: left;
margin-right: 15px;
}
In the react component I'm trying to do something like :
class Test extends React.Component {
constructor(props){
super(props);
this.state = {
left: 0
}
}
handleSwipe(){
this.setState({left: -350})
}
render(){
return(
<div className="outter">
<div className="inner" style={{left: this.state.left}} onSwipe={this.handleSwipe.bind(this)}>
<div className="child"><img src="http://placehold.it/350x150" /></div>
<div className="child"><img src="http://placehold.it/350x150" /></div>
<div className="child"><img src="http://placehold.it/350x150" /></div>
<div className="child"><img src="http://placehold.it/350x150" /></div>
</div>
</div>
)
}
}
React.render(<Test />, document.getElementById('container'));
How can I recognize swipe event?
If I in my example instead of onSwipe
add onClick
it works, but how can I make the swipe effect?
Here is jsfiddle.
See Question&Answers more detail:os