title: Zooming an image aimed at the mouse cursor
body: <p><strong>Use case:</strong></p>
  
  <p>User clicks a link, a modal window is displayed containing one big image, scaled down to fit this window. When the user scrolls their mousewheel up or down, the image zooms in or out. The image is zoomed at whatever location the mouse cursor is pointing.</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>I can't wrap my brain around the how-to part of doing this.</p>
  
  <p><strong>Current workings:</strong></p>
  
  <p>When a link is clicked, a jQuery plugin creates a "viewer" collection of html elements that are styled with CSS. It's an absolute positioned DIV that contains an IMG-element. The image is scaled to 100% width. When scrolling, the image is increased by 5% per scroll action.</p>
  
  <p>Because the image is scaled up whilst zooming in, the containing DIV (overflow: hidden) will eventually clip the image. The image is draggable so that you can always see all parts of it.</p>
  
  <p><strong>Variables I keep and know:</strong></p>
  
  <p>The image's scaled down ratio.
  The image's dimensions pre our most recent zoom action.
  The image's new dimensions after our most recent zoom action.
  The difference in these two dimensions.
  The X and Y position of the image.
  The X and Y position of the mouse cursor, relative to the positioned container DIV.</p>
  
  <p><strong>What I probably need:</strong></p>
  
  <p>I know the variables I need, I just can't grasp in what order to put them and what operators to use when. Math never was my strong suit, neither was grammar. So any help is appreciated.</p>
  
  <p><strong>Research done:</strong></p>
  
  <p>I Googled a lot for existing solutions. Most were implementations of OpenGL or Flash/ActionScript, none of which make any sense to me whatsoever. The few javascript-based examples I found were for commercial purposes, and even then their source code was obfuscated or minified, and I couldn't quite extract the inner workings for this little feature properly.</p>
  
  <p>Also, I probably don't have the correct search words to figure it out, either.</p>