How To Create Minion Eyes That Follows Mouse Cursor

Last Updated: 02-Jan-2022 13:49:29
160 Views
Summarize

Git is a distributed version control system DVCS designed for efficient source code management, suitable for both small and large projects. It allows multiple developers to work on a project simultaneously without overwriting changes, supporting collaborative work, continuous integration, and deployment. This Git and GitHub tutorial is designed for beginners to learn fundamentals and advanced concepts, including branching, pushing, merging conflicts, and essential Git commands. Prerequisites include familiarity with the command line interface CLI, a text editor, and basic programming concepts. Git was developed by Linus Torvalds for Linux kernel development and tracks changes, manages versions, and enables collaboration among developers. It provides a complete backup of project history in a repository. GitHub is a hosting service for Git repositories, facilitating project access, collaboration, and version control. The tutorial covers topics such as Git installation, repository creation, Git Bash usage, managing branches, resolving conflicts, and working with platforms like Bitbucket and GitHub. The text is a comprehensive guide to using Git and GitHub, covering a wide range of topics. It includes instructions on working directories, using submodules, writing good commit messages, deleting local repositories, and understanding Git workflows like Git Flow versus GitHub Flow. There are sections on packfiles, garbage collection, and the differences between concepts like HEAD, working tree, and index. Installation instructions for Git across various platforms Ubuntu, macOS, Windows, Raspberry Pi, Termux, etc. are provided, along with credential setup. The guide explains essential Git commands, their usage, and advanced topics like debugging, merging, rebasing, patch operations, hooks, subtree, filtering commit history, and handling merge conflicts. It also covers managing branches, syncing forks, searching errors, and differences between various Git operations e.g., push origin vs. push origin master, merging vs. rebasing. The text provides a comprehensive guide on using Git and GitHub. It covers creating repositories, adding code of conduct, forking and cloning projects, and adding various media files to a repository. The text explains how to push projects, handle authentication issues, solve common Git problems, and manage repositories. It discusses using different IDEs like VSCode, Android Studio, and PyCharm, for Git operations, including creating branches and pull requests. Additionally, it details deploying applications to platforms like Heroku and Firebase, publishing static websites on GitHub Pages, and collaborating on GitHub. Other topics include the use of Git with R and Eclipse, configuring OAuth apps, generating personal access tokens, and setting up GitLab repositories. The text covers various topics related to Git, GitHub, and other version control systems Key Pointers Git is a distributed version control system DVCS for source code management. Supports collaboration, continuous integration, and deployment. Suitable for both small and large projects. Developed by Linus Torvalds for Linux kernel development. Tracks changes, manages versions, and provides complete project history. GitHub is a hosting service for Git repositories. Tutorial covers Git and GitHub fundamentals and advanced concepts. Includes instructions on installation, repository creation, and Git Bash usage. Explains managing branches, resolving conflicts, and using platforms like Bitbucket and GitHub. Covers working directories, submodules, commit messages, and Git workflows. Details packfiles, garbage collection, and Git concepts HEAD, working tree, index. Provides Git installation instructions for various platforms. Explains essential Git commands and advanced topics debugging, merging, rebasing. Covers branch management, syncing forks, and differences between Git operations. Discusses using different IDEs for Git operations and deploying applications. Details using Git with R, Eclipse, and setting up GitLab repositories. Explains CI/CD processes and using GitHub Actions. Covers internal workings of Git and its decentralized model. Highlights differences between Git version control system and GitHub hosting platform.

2 trials left
Hello Everyone, In today’s tutorial, we will learn how to create minion eyes that follow your mouse cursor. To create this project we need HTML, CSS and Javascript. This project is best suitable for javascript intermediates. Javascript beginners might feel this project is a bit tricky and easy.
Access Our :  Free Online Tools
In this project, we create minion eyes using html, CSS & JavaScript. And to make the eyes follow the mouse, we make use of javascript.

HTML


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Minion Eyes Follow Mouse</title>
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="container">
      <div class="eyes-wrapper">
        <div class="eye">
          <div class="eyeball"></div>
        </div>
        <div class="eye">
          <div class="eyeball"></div>
        </div>
      </div>
    </div>
    <!-- Script -->
    <script src="script.js"></script>
  </body>
</html>

CSS


body {
  padding: 0;
  margin: 0;
  background-color: #f5d60e;
}
.container {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.container:before {
  content: "";
  position: absolute;
  width: 100%;
  height: 4em;
  background-color: #231f1e;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 50%;
  z-index: -1;
}
.eyes-wrapper {
  display: flex;
}
.eyes-wrapper:before {
  content: "";
  position: absolute;
  width: 26em;
  height: 6em;
  background-color: #a8a7ac;
  margin: auto;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: -1;
}
.eye {
  width: 10em;
  height: 10em;
  border: 15px solid #a6a4ad;
  background-color: #ffffff;
  border-radius: 50%;
}
.eyeball {
  height: 3.2em;
  width: 3.2em;
  background: radial-gradient(#271e1e 35%, #935a29 37%);
  border-radius: 50%;
  margin: 0.2em 3.5em;
  position: relative;
}
.eyeball:before {
  content: "";
  position: absolute;
  background-color: #ffffff;
  height: 0.7em;
  width: 0.5em;
  border-radius: 50%;
  top: 13px;
  left: 13px;
  transform: rotate(45deg);
}

JAVASCRIPT

To add follow cursor functionality to these eyes, we have to use javascript. Now again, copy the javascript code that is provided below and paste it into your script.js file.

//Selecting the eye div
let eye_ref = document.querySelectorAll(".eye");

//mousemove for devices with mouse aand touchmove for touchcreen devices
let events = ["mousemove", "touchmove"];

//Check for touch screen
function isTouchDevice() {
  try {
    document.createEvent("TouchEvent");
    return true;
  } catch (e) {
    return false;
  }
}

//Same function for both events
events.forEach((eventType) => {
  document.body.addEventListener(eventType, (event) => {
    eye_ref.forEach((eye) => {
      /* getBoundingClientRect() method returns the position relative to the viewport */
      let eyeX = eye.getBoundingClientRect().left + eye.clientWidth / 2;
      let eyeY = eye.getBoundingClientRect().top + eye.clientHeight / 2;

      /* ClientX and ClientY return the position of clients cursor from top left of the screen*/
      var x = !isTouchDevice() ? event.clientX : event.touches[0].clientX;
      var y = !isTouchDevice() ? event.clientY : event.touches[0].clientY;

      /* 
    Subtract x position of mouse from x position of eye and y position of mouse from y position of eye.
    Use atan2(returns angle in radians)
    */

      let radian = Math.atan2(x - eyeX, y - eyeY);
      //Convert Radians to Degrees
      let rotationDegrees = radian * (180 / Math.PI) * -1 + 180;
      //Rotate the eye
      eye.style.transform = "rotate(" + rotationDegrees + "deg)";
    });
  });
});
Also Read : How To Create Superman Mode Minion Using HTML, CSS & JavaScript
If you wann to check the demo of this code, then you can check using below demo button.
Click on the following download button to download all source code files of minion eyes directly on your computer.

Final Word

In this way, we can create minion eyes using html, css & JavaScriptI hope you all like this tutorial. Keep with us for next tutorial. if you wann the source code of this code you can get this on our github account. If you have any query please free to contact us Or comment below. This is the best and simple project for JavaScript beginner. Every JavaScript beginner use this project for their projects. also we have created HTML course for beginners for absolutely free. This html course is a free tutorial library for every programmer. You can share this with your friends. Thank you !

You may also like this!