title: Javascript: Zoom in on mouseover WITHOUT Jquery or plugins
body: <p>I've looked for this everywhere for weeks, and I simply cannot find something to tell me what I'm doing wrong or how to even proceed. The goal is to create a function similar to Amazon's zoom in on mouseover for products with small images.</p>
  
  <p>I'm currently at a loss for how to proceed, though I am aware that I will require two images- one in the "zoomed in" size and one in the "zoomed out" size. <strong>I'm not using Jquery</strong>- I cannot install it or any plugins to the website via my employer's request. I'm basically asking for the harder answer, and I apologize for that in advance. I must do this from moderate scratch. <strong>Warning</strong>: I am a programming Student. Take that as you will.</p>
  
  <p>I've got HTML and CSS script, and because we don't actually have an IDE here I'm doing this on codecademy's project section, otherwise I'd have to program this completely live. You can find my code <a href="https://www.codecademy.com/kitfoxpup/codebits/9RPoQ1" rel="noreferrer">here</a>, but I'll also post the code below, as that link is bound to have changing code since it uses procedural saving.</p>
  
  <p>Note: I originally had it so that the gray box was following my mouse at relative center. It was flickering as it moved, but it was working. Currently though it's decided not to, at least on my work computer. I've not tested it on my personal computer.</p>
  
  <p>Edit: The code is working on my Surface Pro 3, though it does follow the mouse off of the image (which is temporary and something random I grabbed). I'm not sure why the code isn't working on my work computer, though it's probable because it's a Macintosh OSX version 10.6.8...</p>
  
  <p><strong>HTML Code</strong>:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;link rel='stylesheet' href='style.css'/&gt;
      &lt;script src='script.js'&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;img id="imgZoom" onmousemove="zoomIn()" onmouseout="zoomOut()" src="http://ginger-mum.com/wp-content/uploads/2015/10/3633-1269758855-0da5042c33400a811a5d766be4579cb8.jpg"&gt;
  &lt;div id="overlay" onmousemove="zoomIn()"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>CSS Code</strong>:</p>
  
  <pre><code>#imgZoom {
      height: 300;
  }
  
  #overlay {
      visibility: hidden;
      position: absolute;
      left: 0px;
      top: 0px;
      width:20%;
      height:20%;
      padding: 25px;
      border: 5px solid gray;
      background-color: white;
      opacity:0.4;
      text-align:center;
      z-index: 1000;
  }
  </code></pre>
  
  <p><strong>Javascript code</strong>:</p>
  
  <pre><code>function zoomIn()
  {
      var element = document.getElementById("overlay");
      element.style.visibility = "visible";
  
      var x = event.clientX;     // Get the horizontal coordinate
      var y = event.clientY;     // Get the vertical coordinate
  
      element.style.top = y - 80;
      element.style.left = x - 80;
  }
  
  function zoomOut()
  {
      var element = document.getElementById("overlay");
      element.style.visibility = "hidden";
  }
  </code></pre>