Skip to content

Instantly share code, notes, and snippets.

@Ami777
Created March 2, 2017 13:31
Show Gist options
  • Save Ami777/78c8b10e601c3dc4df6253e6aefd82b5 to your computer and use it in GitHub Desktop.
Save Ami777/78c8b10e601c3dc4df6253e6aefd82b5 to your computer and use it in GitHub Desktop.
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