g3x0

[jQuery] Hover Zoom Effect: Horizontal [RSTForums.com]

Oct 16th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!--
  2.    Everything in here is required for the effect to work.
  3.    This is the source code for the horizontal effect.
  4.  
  5.    author Gecko @RSTForums.com
  6. -->
  7.  
  8. <!-- Stylesheet -->
  9. <style>
  10. .container {
  11.     overflow: hidden;
  12.     width: 400px; /* Container width */
  13. }
  14. .container img {
  15.     position: relative;
  16. }
  17. </style>
  18.  
  19. <!-- Markup -->
  20. <div class="container">
  21.     <img src="http://www.g3x0.com/rst/images/mago-huge.jpg" />
  22. </div>
  23.  
  24. <!-- jQuery -->
  25. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  26.  
  27. <!-- Hover Zoom Effect -->
  28. <script>
  29. $(function() {
  30.     var container = $(".container");
  31.    
  32.     container.mousemove(function(e) {
  33.         var parentOffset = $(this).offset();
  34.         var x = e.pageX - parentOffset.left;
  35.         var image = $(this).find('img');
  36.  
  37.         if (image.width() > $(this).width())
  38.             image.css({ left: - x / $(this).width() * image.width() + x + 'px' });
  39.     });
  40.  
  41. });
  42. </script>
Advertisement
Add Comment
Please, Sign In to add comment