File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,17 @@ class ListContainer extends PureComponent {
4040 this . setState ( {
4141 left : - this . perDistance * index ,
4242 } ) ;
43- }
43+ }
44+
45+ componentWillReceiveProps ( nextProps ) {
46+ if ( this . props . index !== nextProps . index ) {
47+ this . isNeedSpring = true ;
48+ this . setState ( {
49+ left : - this . perDistance * nextProps . index ,
50+ } ) ;
51+ }
52+ }
53+
4454 /**
4555 * 拖拽的缓动公式 - easeOutSine
4656 * Link http://easings.net/zh-cn#
Original file line number Diff line number Diff line change @@ -5,21 +5,24 @@ class Pointer extends PureComponent {
55 static propTypes = {
66 length : PropTypes . number . isRequired ,
77 index : PropTypes . number . isRequired ,
8+ changeIndex : PropTypes . func
89 }
910
1011 render ( ) {
1112 console . info ( "Point render" )
1213
1314 const {
1415 length,
16+ changeIndex,
1517 index
1618 } = this . props
19+
1720 let i = 0 , items = [ ] ;
1821 for ( i ; i < length ; i ++ ) {
1922 if ( i === index ) {
20- items . push ( < span key = { i } className = "pointer on" > </ span > ) ;
23+ items . push ( < span onClick = { changeIndex . bind ( null , i ) } key = { i } className = "pointer on" > </ span > ) ;
2124 } else {
22- items . push ( < span key = { i } className = "pointer" > </ span > ) ;
25+ items . push ( < span onClick = { changeIndex . bind ( null , i ) } key = { i } className = "pointer" > </ span > ) ;
2326 }
2427 }
2528
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ class WrapViewer extends Component {
6666 urls = { urls }
6767 gap = { gap }
6868 index = { index } />
69- < Pointer length = { urls . length } index = { index } />
69+ < Pointer length = { urls . length } index = { index } changeIndex = { this . changeIndex } />
7070 </ div >
7171 ) ;
7272 }
You can’t perform that action at this time.
0 commit comments