-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevator.js
79 lines (68 loc) · 2.14 KB
/
elevator.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
$(document).ready(function(){
var cur_floor=1;
queue = [];
moving = false;
$('.part:not(.glow)').click(function(event){
var floor_number = $(this).attr('floor-number');
if (floor_number == cur_floor) return;
$(this).addClass('glow');
if(queue.indexOf(floor_number) == -1){
queue.push(floor_number);
checkAndRun();
}
});
function checkAndRun(){
if (moving === false && queue.length > 0){
moveToFloor(queue.shift());
}
}
function moveToFloor(target_floor){
moving = true;
var direction = 1;
var indicator = $('#up');
if (target_floor < cur_floor) {
direction = -1;
indicator = $('#down');
}
indicator.animate({opacity:1}, 500);
var timer = setInterval(function(){
cur_floor += direction;
$('#floor-number').fadeOut(500,function(){
$('#floor-number').html(cur_floor).fadeIn(500);
});
if(cur_floor == target_floor){
clearInterval(timer);
setTimeout(function(){
indicator.animate({opacity:0},500,function(){
$('.part[floor-number="'+target_floor+'"]').removeClass('glow');
moving = false;
setTimeout(function(){
checkAndRun();
},1000);
});
},1500);
}
},1500);
}
});
////////////////////////////////////////////////////////////
/*var current = 0;
$(document).ready(function(){
$("#floorSelect li").click(function(){
var floor = parseInt($(this).data("floor")),
height = floor * 20,
animate = Math.abs(current - floor) * 1000;
if (floor == current) return;
$("#rightDoor").removeClass("active-right");
$("#leftDoor").removeClass("active-left");
setTimeout(function() {
$("#elevatorContainer").css("transition", "all " + animate + "ms linear");
$("#elevatorContainer").css("bottom", height + "%");
current = floor;
setTimeout(function() {
$("#rightDoor").addClass("active-right");
$("#leftDoor").addClass("active-left");
},animate);
},300);
});
});*/