Advertisement
Guest User

Untitled

a guest
Jun 29th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;(function () {
  2.         var xPosAbs = [],
  3.             yHoverPosAbs = 82,
  4.             yActivePosAbs = 164,
  5.             activeKlass = 'nav__item_current';
  6.  
  7.         function applyBgPos(elem, isHovering) {
  8.             var yPos = elem.hasClass(activeKlass) ? yActivePosAbs : isHovering ? yHoverPosAbs : 0;
  9.  
  10.             elem
  11.                 .find('.nav__txt')
  12.                 .css({'backgroundPosition': -xPosAbs[elem.index()] + 'px -' + yPos + 'px'});
  13.         }
  14.  
  15.         $.each($('.nav__item'), function () {
  16.             var $item = $(this);
  17.  
  18.             xPosAbs.push($item.position().left);
  19.             applyBgPos($item);
  20.         });
  21.  
  22.         $(document)
  23.             .on('mouseenter', '.nav__item', function (e) {
  24.                     applyBgPos($(this), true);
  25.             })
  26.             .on('mouseleave', '.nav__item', function (e) {
  27.                 var $item = $(this);
  28.  
  29.                 if (!$item.hasClass(activeKlass)) {
  30.                     $item
  31.                             .find('.nav__txt')
  32.                             .css({
  33.                                 'backgroundPosition': ''
  34.                             })
  35.                 }
  36.             });
  37.     }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement