-
Notifications
You must be signed in to change notification settings - Fork 1
/
rotate.html
164 lines (140 loc) · 5.05 KB
/
rotate.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
padding: 0;margin: 0;
box-sizing: border-box;
}
.wrap{
position: relative;
width: 380px;
height: 100px;
margin: 10px 0;
}
.wrap p{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: transform 1s linear;
background: orange;
color: #000;
backface-visibility: hidden;
line-height: 1.4;
text-indent: 1rem;
font-size: 1rem;
overflow: hidden;
}
.wrap p span{
display: block;
width: 100%;
padding: 5px;
}
.active{
transform: rotateX(180deg);
}
</style>
</head>
<body>
<div id="root"></div>
<!-- <script src="lib/jquery.js"></script> -->
<script src="lib/react.js"></script>
<script src="lib/react-dom.js"></script>
<script src="lib/babel.min.js"></script>
<script type="text/babel">
// 每一个新闻条的组件
class NewsItem extends React.Component{
constructor(props){
super(props);
this.state = {
flag:false
}
this.rotate=this.rotate.bind(this);
this.setIndex=this.setIndex.bind(this);
}
rotate(){
this.setState({
flag:!this.state.flag
})
}
componentWillReceiveProps(props){
if(props['data-key'] == props.index){
console.log('当前子组件的key是:'+props['data-key']);
setTimeout(()=>this.rotate(),1500)
}
}
componentDidMount(){
setTimeout(()=> {
if(this.props['data-key'] == this.props.index){
console.log('当前子组件的key是:'+this.props['data-key'])
//console.log(props);
this.rotate();
}
}, 1000);
}
setIndex(){
this.props.changeIndexFn(this.props['data-key'])
}
render(){
return (
<div className="wrap">
<p className={this.state.flag?'active':''} onTransitionEnd={this.setIndex}>
<span className="title">中国央行副行长殷勇:人民币能在...</span>
<span className="detail">中国在提供人民币资金方面更有相对竞争优势,人民币应该能够在建设中发挥更大作用</span>
</p>
<p className={this.state.flag?'':'active'}>
<span className="title">title</span>
<span className="detail">content</span>
</p>
</div>
)
}
};
//所有新闻的容器组件
class Wrap extends React.Component {
constructor(props){
super(props);
this.state={
index:0
};
this.changeIndex= this.changeIndex.bind(this)
}
changeIndex(key){
console.log(key);
this.setState(function(state) {
state.index= key<4?key+1:0
})
}
render(){
return (
<div>
{[
<NewsItem index={this.state.index} changeIndexFn={this.changeIndex} key={0} data-key={0} />,
<NewsItem index={this.state.index} changeIndexFn={this.changeIndex} key={1} data-key={1} />,
<NewsItem index={this.state.index} changeIndexFn={this.changeIndex} key={2} data-key={2} />,
<NewsItem index={this.state.index} changeIndexFn={this.changeIndex} key={3} data-key={3} />,
<NewsItem index={this.state.index} changeIndexFn={this.changeIndex} key={4} data-key={4} />
]}
</div>
)
}
}
ReactDOM.render(
<Wrap />,
document.getElementById('root')
)
/* $.ajax('data/newslist.json').then(function(data) {
ReactDOM.render(
<Wrap list={data.resultList}/>,
document.getElementById('root')
)
}) */
</script>
</body>
</html>