SHARE
TWEET

Untitled

a guest Jul 21st, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function()
  2. {
  3.     var scale = 1;  // scale of the image
  4.     var xLast = 0;  // last x location on the screen
  5.     var yLast = 0;  // last y location on the screen
  6.     var xImage = 0; // last x location on the image
  7.     var yImage = 0; // last y location on the image
  8.  
  9.     // if mousewheel is moved
  10.     $("#mosaicContainer").mousewheel(function(e, delta)
  11.     {
  12.         // find current location on screen
  13.         var xScreen = e.pageX - $(this).offset().left;
  14.         var yScreen = e.pageY - $(this).offset().top;
  15.  
  16.         // find current location on the image at the current scale
  17.         xImage = xImage + ((xScreen - xLast) / scale);
  18.         yImage = yImage + ((yScreen - yLast) / scale);
  19.  
  20.         // determine the new scale
  21.         if (delta > 0)
  22.         {
  23.             scale *= 2;
  24.         }
  25.         else
  26.         {
  27.             scale /= 2;
  28.         }
  29.         scale = scale < 1 ? 1 : (scale > 64 ? 64 : scale);
  30.  
  31.         // determine the location on the screen at the new scale
  32.         var xNew = (xScreen - xImage) / scale;
  33.         var yNew = (yScreen - yImage) / scale;
  34.  
  35.         // save the current screen location
  36.         xLast = xScreen;
  37.         yLast = yScreen;
  38.  
  39.         // redraw
  40.         $(this).find('div').css('-moz-transform', 'scale(' + scale + ')' + 'translate(' + xNew + 'px, ' + yNew + 'px' + ')')
  41.                            .css('-moz-transform-origin', xImage + 'px ' + yImage + 'px')
  42.         return false;
  43.     });
  44. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top