Created
March 2, 2017 13:31
-
-
Save Ami777/78c8b10e601c3dc4df6253e6aefd82b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
document.addEventListener('DOMContentLoaded', function(){ | |
class CrazyDiv extends React.Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
left : '0', | |
top: '0', | |
}; | |
} | |
handleDivMouseMove = () => { | |
const top = Math.round( Math.random() * 1000 ) + 'px'; | |
const left = Math.round( Math.random() * 1000 ) + 'px'; | |
this.setState({ | |
top, | |
left, | |
}); | |
}; | |
render(){ | |
return <div style={{ | |
width : '100px', | |
height : '100px', | |
position : 'absolute', | |
backgroundColor : 'red', | |
left : this.state.left, | |
top : this.state.top | |
}} | |
onMouseEnter={this.handleDivMouseMove} | |
/>; | |
} | |
} | |
class App extends React.Component { | |
render(){ | |
return <CrazyDiv />; | |
} | |
} | |
ReactDOM.render( | |
<App />, | |
document.getElementById('app') | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment