-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.magicMenu.js
51 lines (45 loc) · 1.28 KB
/
jquery.magicMenu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**********************************
Magic menú is developed by memoadian
http://comprar-web.com
License MIT Creative Commons
Credits magic line tutorial by http://css-tricks.com
**********************************/
(function( $ ) {
$.fn.magicMenu = function(options){
var settings = $.extend( {
'speed':300,
'easing':'swing'
}, options);
$mainNav = this;
$mainNav.append("<li id='magic-line'><p></p></li>");
$magicLine = $("#magic-line p");
$magic = $("#magic-line");
$magicLine
.width($(".current_item").width())
.data("origWidth", $magicLine.width());
$magic
.data("origLeft", $(".current_item a").position().left)
.css({
"left": $(".current_item a").position().left,
});
$(" > li", $mainNav).hover(function() {
$el = $(" > a", this);
$leftPos = $el.position().left;
$newWidth = $el.parent().width();
$magicLine.stop().animate({
width: $newWidth
},settings.speed, settings.easing);
$magic.stop().animate({
left: $leftPos,
},settings.speed, settings.easing);
}, function() {
$magicLine.stop().animate({
width: $magicLine.data("origWidth")
},settings.speed, settings.easing);
$magic.stop().animate({
left: $magic.data("origLeft"),
},settings.speed, settings.easing);
});
return this;
};
})( jQuery );