Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react";
  2. import "./App.css";
  3. import cat from "./iu.png";
  4.  
  5. class App extends Component {
  6.   constructor(props) {
  7.     super(props);
  8.  
  9.     this.state = { x: 0, y: 0 };
  10.   }
  11.   handleMouseMove = e => {
  12.     this.setState({ x: e.screenX, y: e.screenY });
  13.   };
  14.  
  15.   // handleTracking = () => <img className="App-img" src={cat} alt="cat" />;
  16.  
  17.   render() {
  18.     const { x, y } = this.state;
  19.     const imgStyle = {
  20.       width: "100px",
  21.       height: "100px",
  22.       position: "absolute",
  23.       top: this.state.y + "px",
  24.       left: this.state.x + "px",
  25.       marginTop: "-50px",
  26.       marginLeft: "-50px"
  27.     };
  28.    
  29.     return (
  30.       <div className="App">
  31.         <div className="App-header" onMouseMove={this.handleMouseMove}>
  32.           <h3>
  33.             <img style={imgStyle} src={cat} alt="cat" />
  34.             coordinates:
  35.             {x} | {y}
  36.           </h3>
  37.         </div>
  38.       </div>
  39.     );
  40.   }
  41. }
  42.  
  43. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement