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
| var Demo = React.createClass({ getInitialState:function(){ return { width: 200, height: 200, backgroundColor: '#DDDDDD' } },
randomColor:function(){ var r = Math.floor(Math.random()*256); var g = Math.floor(Math.random()*256); var b = Math.floor(Math.random()*256); return 'rgb('+r+','+g+','+b+')' }, handleWheel:function(){ this.setState({ backgroundColor:this.randomColor() }) }, render:function(){ return <div onWheel={this.handleWheel} style={this.state}>这是一个案例,鼠标滚动实现背景颜色的变化</div> } }) ReactDOM.render(<Demo/>,document.getElementById('app'))
|