Skip to content

Commit 6449c58

Browse files
李钿李钿
authored andcommitted
指示器增加点击切换功能
1 parent c23dbe1 commit 6449c58

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/components/ListContainer.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff 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#

src/components/Pointer.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff 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

src/components/WrapViewer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)