Advertisement
Shiny_

Untitled

Jul 11th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.30 KB | None | 0 0
  1.  
  2. $(window).load(function() {
  3.     $outer_container=$("#outer_container");
  4.     $imagePan_panning=$("#imagePan .panning");
  5.     $imagePan=$("#imagePan");
  6.     $imagePan_container=$("#imagePan .container");
  7.  
  8.     $imagePan_panning.css("margin-top",($imagePan.height()-$imagePan_panning.height())/2+"px");
  9.     containerWidth=$imagePan.width();
  10.     containerHeight=$imagePan.height();
  11.     totalContentW=$imagePan_panning.width();
  12.     totalContentH=$imagePan_panning.height();
  13.     $imagePan_container.css("width",totalContentW).css("height",totalContentH);
  14.  
  15.     function MouseMove(e){
  16.         var mouseCoordsX=(e.pageX - $imagePan.offset().left);
  17.         var mouseCoordsY; //=(e.pageY - $imagePan.offset().top);
  18.         var mousePercentX=mouseCoordsX/containerWidth;
  19.         var mousePercentY=mouseCoordsY/containerHeight;
  20.         var destX=-(((totalContentW-(containerWidth))-containerWidth)*(mousePercentX));
  21.         var destY=-(((totalContentH-(containerHeight))-containerHeight)*(mousePercentY));
  22.         var thePosA=mouseCoordsX-destX;
  23.         var thePosB=destX-mouseCoordsX;
  24.         var thePosC=mouseCoordsY-destY;
  25.         var thePosD=destY-mouseCoordsY;
  26.         var marginL=$imagePan_panning.css("marginLeft").replace("px", "");
  27.         var marginT=$imagePan_panning.css("marginTop").replace("px", "");
  28.         var animSpeed=1000; //ease amount
  29.         var easeType="easeOutCirc";
  30.         if(mouseCoordsX>destX || mouseCoordsY>destY){
  31.             //$imagePan_container.css("left",-thePosA-marginL); $imagePan_container.css("top",-thePosC-marginT); //without easing
  32.             $imagePan_container.stop().animate({left: -thePosA-marginL, top: -thePosC-marginT}, animSpeed,easeType); //with easing
  33.         } else if(mouseCoordsX<destX || mouseCoordsY<destY){
  34.             //$imagePan_container.css("left",thePosB-marginL); $imagePan_container.css("top",thePosD-marginT); //without easing
  35.             $imagePan_container.stop().animate({left: thePosB-marginL, top: thePosD-marginT}, animSpeed,easeType); //with easing
  36.         } else {
  37.             $imagePan_container.stop();
  38.         }
  39.     }
  40.  
  41.     $imagePan_panning.css("margin-left",($imagePan.width()-$imagePan_panning.width())/2).css("margin-top",($imagePan.height()-$imagePan_panning.height())/2);
  42.  
  43.     $imagePan.bind("mousemove", function(event){
  44.         MouseMove(event);                                    
  45.     });
  46. });
  47.  
  48. $(window).resize(function() {
  49.     $imagePan.unbind("mousemove");
  50.     $imagePan_container.css("top",0).css("left",0);
  51.     $(window).load();
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement