-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (52 loc) · 1.74 KB
/
script.js
File metadata and controls
63 lines (52 loc) · 1.74 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
$(function () {
var $mainMenuItems = $("#main-menu ul").children("li"),
totalMainMenuItems = $mainMenuItems.length,
openedIndex = 2,
init = function () {
bindEvents();
if (validIndex(openedIndex))
animateItem($mainMenuItems.eq(openedIndex), true, 700);
},
bindEvents = function () {
$mainMenuItems.children(".images").click(function () {
var newIndex = $(this).parent().index();
checkAndAnimateItem(newIndex);
});
$(".button").hover(
function () {
$(this).addClass("hovered");
},
function () {
$(this).removeClass("hovered");
}
);
$(".button").click(function () {
var newIndex = $(this).index();
checkAndAnimateItem(newIndex);
});
},
validIndex = function (indexToCheck) {
return (indexToCheck >= 0) && (indexToCheck < totalMainMenuItems);
},
animateItem = function ($item, toOpen, speed) {
var $colorImage = $item.find(".color"),
itemParam = toOpen ? { width: "420px" } : { width: "140px" },
colorImageParam = toOpen ? { left: "0px" } : { left: "140px" };
$colorImage.animate(colorImageParam, speed);
$item.animate(itemParam, speed);
},
checkAndAnimateItem = function (indexToCheckAndAnimate) {
if (openedIndex === indexToCheckAndAnimate) {
animateItem($mainMenuItems.eq(indexToCheckAndAnimate), false, 250);
openedIndex = -1;
}
else {
if (validIndex(indexToCheckAndAnimate)) {
animateItem($mainMenuItems.eq(openedIndex), false, 250);
openedIndex = indexToCheckAndAnimate;
animateItem($mainMenuItems.eq(openedIndex), true, 250);
}
}
};
init();
});