-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.js
121 lines (76 loc) · 3.62 KB
/
animation.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var object=document.querySelector(".shuttle img");
var button=document.querySelector('.start-btn');
var racket=document.querySelector('.racket');
var racket2=document.querySelector('.racket-2');
var pos=1,pos_rotate=1,flag=0,left_side=1, upward_movement=0,timer;
button.addEventListener('click', function(){
if(button.innerHTML== "START")
{ button.innerHTML="STOP";
timer= setInterval(move,1);
}
else{
clearInterval(timer);
button.innerHTML="START";
}
});
function move(){ // to move the shuttle across the net
if(parseInt(object.style.bottom)== 0) flag=1; // when shuttle comes from right to left
if(parseInt(object.style.bottom)==0 && left_side ==1 ){ // when shuttle comes from left to right
flag=0;
pos=1;
}
if(flag==0) //left to right
{
racket.style.transform ="rotate(30deg)";
left_side=0;
object.style.left = + pos + 'px';
pos+=1;
if( parseInt(object.style.left) >=screen.width/6 && parseInt(object.style.left) <=screen.width/4) {
upward_movement+=1/4; // upward movement of shuttle
object.style.bottom = + upward_movement + 'px';
}
else if( parseInt(object.style.left) >=screen.width/4 && parseInt(object.style.left) <=screen.width/2) {
upward_movement+=0.2;
object.style.bottom = + upward_movement + 'px';
}
else if(parseInt(object.style.left) >=screen.width/2 && parseInt(object.style.left)<screen.width/1.5){
object.style.bottom = upward_movement+ 'px';
}
else if(parseInt(object.style.left) >=screen.width/1.5){
object.style.left = + pos + 'px';
upward_movement-=0.7; // downward movement of shuttle
object.style.bottom = upward_movement+ 'px';
racket2.style.transform="rotate(-30deg)";
}
else{
upward_movement+=1;
object.style.bottom = + upward_movement + 'px';}
}
if(flag==1) // right to left
{ racket2.style.transform="rotate(30deg)";
left_side=1;
pos-=1;
object.style.left = + pos + 'px';
if(parseInt(object.style.left) <=screen.width/1.1 && parseInt(object.style.left) >screen.width/1.5){
upward_movement+=0.7; // upward movement
object.style.bottom = upward_movement+ 'px';
}
else if(parseInt(object.style.left) <=screen.width/1.5 && parseInt(object.style.left) >screen.width/1.8){
object.style.left = + pos + 'px';
upward_movement-=0;
object.style.bottom = upward_movement+ 'px';
racket.style.transform ="rotate(-30deg )";
}
else if(parseInt(object.style.left) <=screen.width/1.8){
object.style.left = + pos + 'px';
upward_movement-=0.5; // downward movement of shuttle
object.style.bottom = upward_movement+ 'px';
}
else{
upward_movement+=1;
object.style.bottom = + upward_movement + 'px';
}
}
object.style.transform = " rotate("+pos_rotate+"deg )"; // rotating shuttle
pos_rotate +=0.4;
}