Advertisement
Guest User

Untitled

a guest
Aug 27th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $.fn.zoomtabs = function (zoomPercent, easing) {
  2.     if (!zoomPercent) zoomPercent = 10;
  3.    
  4.     return this.each(function () {
  5.  
  6.         var $zoomtab = $(this);
  7.  
  8.         var $tabs = $zoomtab.find('.tabs');
  9.  
  10.         var height = $tabs.height();
  11.        
  12.         var panelIds = $tabs.find('a').map(function () {
  13.             return this.hash;
  14.         }).get().join(',');
  15.        
  16.         $zoomtab.find('> div').scrollTop(0);
  17.        
  18.         var $panels = $zoomtab.find(panelIds);
  19.  
  20.         var images = [];
  21.        
  22.         $panels.each(function () {
  23.             var $panel = $(this);
  24.             var url = $panel[0].getAttribute("img");
  25.             if (url){
  26.                 $panel[0].setAttribute('style','background: url('+url+') no-repeat center center');
  27.             }
  28.  
  29.             var bg = ($panel.css('backgroundImage') || "").match(/url\s*\(["']*(.*?)['"]*\)/),
  30.                 img = null;
  31.            
  32.             if (bg !== null && bg.length && bg.length > 0) {
  33.                 bg = bg[1];
  34.                 img = new Image();
  35.                
  36.                 $panel.find('*').wrap('<div style="position: relative; z-index: 2;" />');                    
  37.                 $panel.css('backgroundImage', 'none');
  38.                
  39.                 $(img).load(function () {
  40.                     var w = this.width / 10;
  41.                     var wIn = w / 100 * zoomPercent;
  42.                     var h = this.height / 10;
  43.                     var hIn = h / 100 * zoomPercent;
  44.                     var top = 0;
  45.                    
  46.                     var fullView = {
  47.                         height: h + 'em',
  48.                         width: w + 'em',
  49.                         top: top,
  50.                         left: 0
  51.                     };
  52.                                            
  53.                     var zoomView = {
  54.                         height: (h + hIn) + 'em',
  55.                         width: (w + wIn) + 'em',
  56.                         top: top,
  57.                         left: '-' + (wIn / 2) + 'em'
  58.                     };
  59.                    
  60.                     $(this).data('fullView', fullView).data('zoomView', zoomView).css(zoomView);
  61.  
  62.                 }).prependTo($panel).css({'position' : 'absolute', 'top' : 0, 'left' : 0 }).attr('src', bg);
  63.                
  64.                 images.push(img);
  65.             }
  66.         });
  67.  
  68.         function zoomImages(zoomType, speed) {
  69.             $(images).each(function () {
  70.                 var $image = $(this);
  71.  
  72.                 var parent = $image.offsetParent().offsetParent();
  73.                
  74.                 if (parent[0]==$zoomtab[0]){
  75.                
  76.  
  77.                     if ($image.is(':visible')) {
  78.                         $image.stop().animate($image.data(zoomType), speed, easing);
  79.                     } else {
  80.                         $image.css($image.data(zoomType), speed);
  81.                     }
  82.                 }
  83.             });
  84.         }
  85.                    
  86.         $tabs.height(0).hide(); // have to manually set the initial state to get it animate properly.
  87.        
  88.         // this causes opear to render the images with zero height and width for the hidden image
  89.         // $panels.hide().filter(':first').show();
  90.         var speed = 200;
  91.        
  92.         $zoomtab.hover(function () {
  93.             // show and zoom out
  94.             zoomImages('fullView', speed);
  95.             $tabs.stop().animate({ height : height }, speed, easing);
  96.             $tabs.show();
  97.         }, function () {
  98.             // hide and zoom in
  99.             zoomImages('zoomView', speed);
  100.             $tabs.stop().animate({ height : 0 }, speed, easing, function () {
  101.               $tabs.hide();
  102.             });
  103.         });
  104.        
  105.         var hoverIntent = null;
  106.         $tabs.find('a').hover(function () {
  107.             clearTimeout(hoverIntent);
  108.             var el = this;
  109.             hoverIntent = setTimeout(function () {
  110.              
  111.               $panels.hide().filter(el.hash).show();
  112.             }, 100);
  113.         }, function () {
  114.             clearTimeout(hoverIntent);
  115.         }).click(function () {
  116.             return false;
  117.         });
  118.     });
  119. };
  120.  
  121. $(function () {
  122.     $('.zoomoutmenu').zoomtabs(15);
  123. });
  124.  
  125.  
  126. **In html:**
  127.  
  128.   <div class="zoomoutmenu">
  129.     <ul class="tabs">
  130.         <li><a href="#one">One</a></li>
  131.         <li><a href="#two">Two</a></li>
  132.         <li><a href="#three">Three</a></li>
  133.         <li><a href="#four">Four</a></li>
  134.         <li><a href="#five">Five</a></li>
  135.     </ul>
  136.     <div class="panels">
  137.       <div id="one" class="panel" img="YOURS IMAGE">
  138.       </div>
  139.       <div id="two" class="panel" img="YOURS IMAGE">
  140.       </div>
  141.       <div id="three" class="panel" img="YOURS IMAGE">
  142.       </div>
  143.       <div id="four" class="panel" img="YOURS IMAGE">
  144.       </div>
  145.       <div id="five" class="panel" img="YOURS IMAGE">
  146.       </div>        
  147.     </div>
  148.   </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement