-
Notifications
You must be signed in to change notification settings - Fork 0
/
react_demo08.html
45 lines (43 loc) · 1.45 KB
/
react_demo08.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
<!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>生命周期实例</title>
<link rel="stylesheet" href="css/style.css">
<script src="./common/react.js"></script>
<script src="./common/react-dom.js"></script>
<script src="https://cdn.bootcss.com/babel-core/5.8.38/browser.js"></script>
</head>
<body>
<div id="reactContainer"></div>
<script type="text/babel">
var Hello = React.createClass({
getInitialState: function () {
return {opacity: 1.0}
},
componentDidMount: function () {
setInterval(function (){
var opacity = this.state.opacity;
opacity -= 0.05;
if (opacity < 0.1) {
opacity = 1.0
}
this.setState ({
opacity:opacity
})
}.bind(this),100)
},
render : function() {
return (
<div style={{opacity:this.state.opacity}}>
<h2>Hello {this.props.name}</h2>
</div>
)
}
})
ReactDOM.render(<Hello name="zengkai"/>,document.getElementById("reactContainer"))
</script>
</body>
</html>