Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;(function () {
- var xPosAbs = [],
- yHoverPosAbs = 82,
- yActivePosAbs = 164,
- activeKlass = 'nav__item_current';
- function applyBgPos(elem, isHovering) {
- var yPos = elem.hasClass(activeKlass) ? yActivePosAbs : isHovering ? yHoverPosAbs : 0;
- elem
- .find('.nav__txt')
- .css({'backgroundPosition': -xPosAbs[elem.index()] + 'px -' + yPos + 'px'});
- }
- $.each($('.nav__item'), function () {
- var $item = $(this);
- xPosAbs.push($item.position().left);
- applyBgPos($item);
- });
- $(document)
- .on('mouseenter', '.nav__item', function (e) {
- applyBgPos($(this), true);
- })
- .on('mouseleave', '.nav__item', function (e) {
- var $item = $(this);
- if (!$item.hasClass(activeKlass)) {
- $item
- .find('.nav__txt')
- .css({
- 'backgroundPosition': ''
- })
- }
- });
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement