forked from DannyDelott/BetterInterval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anim.js
69 lines (55 loc) · 1.42 KB
/
anim.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
// put elements on page
document.write('<link rel=\"stylesheet\" type=\"text\/css\" href=\"style.css\">');
document.write('<div class=\"circle clearclick\"><div class=\"arc\"><\/div><\/div>');
/* ******************
* GLOBAL VARIABLES *
* ******************/
window.$circle = $('.circle');
window.$arc = $('.arc');
/* ******************
* GLOBAL FUNCTIONS *
* ******************/
window.betterInterval = function(execute, timeout) {
execute.stop = false;
execute.stopped = false;
(function subroutine() {
setTimeout(function() {
if(!execute.stop){
execute();
subroutine();
}else{ execute.stopped = true; }
}, timeout);
})();
};
window.rotateArc = function(){
$arc.toggleClass('counterclockwise');
$arc.toggleClass('clockwise');
};
/* **************
* BEGIN JQUERY *
* **************/
$(function(){
/* ****************
* EVENT HANDLERS *
* ****************/
$circle.on('click', function(){
$circle.toggleClass('clearclick');
$circle.toggleClass('click');
if(rotateArc.stopped){
// console.log('restart arc');
betterInterval(rotateArc, 2000);
}else {
// console.log('stop arc');
rotateArc.stop = true;
}
});
$circle.on('click', function(){
$arc.toggleClass('pause');
});
/* **************
* DEFAULT CODE *
* **************/
$arc.toggleClass('clockwise');
$arc.offset();
betterInterval(rotateArc, 2000);
});