Skip to content

Commit 550b637

Browse files
committed
Gotta love non-self-executing functions.
+error handling +animation +works
1 parent 39e2041 commit 550b637

File tree

4 files changed

+162
-18
lines changed

4 files changed

+162
-18
lines changed

animate-custom.css

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
.animated{-webkit-animation-fill-mode:both;-moz-animation-fill-mode:both;-ms-animation-fill-mode:both;-o-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:1s;-moz-animation-duration:1s;-ms-animation-duration:1s;-o-animation-duration:1s;animation-duration:1s;}.animated.hinge{-webkit-animation-duration:1s;-moz-animation-duration:1s;-ms-animation-duration:1s;-o-animation-duration:1s;animation-duration:1s;}@-webkit-keyframes flipInY {
2+
0% {
3+
-webkit-transform: perspective(400px) rotateY(90deg);
4+
opacity: 0;
5+
} 40% {
6+
-webkit-transform: perspective(400px) rotateY(-10deg);
7+
}
8+
9+
70% {
10+
-webkit-transform: perspective(400px) rotateY(10deg);
11+
}
12+
13+
100% {
14+
-webkit-transform: perspective(400px) rotateY(0deg);
15+
opacity: 1;
16+
}
17+
}
18+
@-moz-keyframes flipInY {
19+
0% {
20+
-moz-transform: perspective(400px) rotateY(90deg);
21+
opacity: 0;
22+
}
23+
24+
40% {
25+
-moz-transform: perspective(400px) rotateY(-10deg);
26+
}
27+
28+
70% {
29+
-moz-transform: perspective(400px) rotateY(10deg);
30+
}
31+
32+
100% {
33+
-moz-transform: perspective(400px) rotateY(0deg);
34+
opacity: 1;
35+
}
36+
}
37+
@-o-keyframes flipInY {
38+
0% {
39+
-o-transform: perspective(400px) rotateY(90deg);
40+
opacity: 0;
41+
}
42+
43+
40% {
44+
-o-transform: perspective(400px) rotateY(-10deg);
45+
}
46+
47+
70% {
48+
-o-transform: perspective(400px) rotateY(10deg);
49+
}
50+
51+
100% {
52+
-o-transform: perspective(400px) rotateY(0deg);
53+
opacity: 1;
54+
}
55+
}
56+
@keyframes flipInY {
57+
0% {
58+
transform: perspective(400px) rotateY(90deg);
59+
opacity: 0;
60+
}
61+
62+
40% {
63+
transform: perspective(400px) rotateY(-10deg);
64+
}
65+
66+
70% {
67+
transform: perspective(400px) rotateY(10deg);
68+
}
69+
70+
100% {
71+
transform: perspective(400px) rotateY(0deg);
72+
opacity: 1;
73+
}
74+
}
75+
76+
.flipInY {
77+
-webkit-backface-visibility: visible !important;
78+
-webkit-animation-name: flipInY;
79+
-moz-backface-visibility: visible !important;
80+
-moz-animation-name: flipInY;
81+
-o-backface-visibility: visible !important;
82+
-o-animation-name: flipInY;
83+
backface-visibility: visible !important;
84+
animation-name: flipInY;
85+
}
86+
@-webkit-keyframes fadeInDownBig {
87+
0% {
88+
opacity: 0;
89+
-webkit-transform: translateY(-2000px);
90+
}
91+
92+
100% {
93+
opacity: 1;
94+
-webkit-transform: translateY(0);
95+
}
96+
}
97+
98+
@-moz-keyframes fadeInDownBig {
99+
0% {
100+
opacity: 0;
101+
-moz-transform: translateY(-2000px);
102+
}
103+
104+
100% {
105+
opacity: 1;
106+
-moz-transform: translateY(0);
107+
}
108+
}
109+
110+
@-o-keyframes fadeInDownBig {
111+
0% {
112+
opacity: 0;
113+
-o-transform: translateY(-2000px);
114+
}
115+
116+
100% {
117+
opacity: 1;
118+
-o-transform: translateY(0);
119+
}
120+
}
121+
122+
@keyframes fadeInDownBig {
123+
0% {
124+
opacity: 0;
125+
transform: translateY(-2000px);
126+
}
127+
128+
100% {
129+
opacity: 1;
130+
transform: translateY(0);
131+
}
132+
}
133+
134+
.fadeInDownBig {
135+
-webkit-animation-name: fadeInDownBig;
136+
-moz-animation-name: fadeInDownBig;
137+
-o-animation-name: fadeInDownBig;
138+
animation-name: fadeInDownBig;
139+
}

app.css

+10
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@
55
margin: 0;
66
padding: 0;
77
}
8+
9+
img.frame {
10+
max-width: 64px;
11+
max-height: 64px;
12+
margin: 5px;
13+
}
14+
15+
#error {
16+
color: red;
17+
}

app.js

+8-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ $(function(){
44
var $results = $('#results');
55
var $frames = $('#frames');
66
var $done = $('#done');
7+
var $error = $('#error');
78

89
var icon;
910
(function(){
@@ -12,10 +13,10 @@ $(function(){
1213
var ctx = c.getContext('2d');
1314
var $link = $('<link rel="icon">').appendTo($head);
1415
icon = function(f){
15-
f(ctx,c,0,null,5,false,undefined,NaN,'NaNaN');
16+
f(ctx,c);
1617
$link.attr('href',c.toDataURL('image/png'));
1718
};
18-
});
19+
})();
1920

2021
var gif;
2122

@@ -48,6 +49,7 @@ $(function(){
4849
gif.render();
4950
}catch(e){
5051
$done.addClass('failed').text('Failed');
52+
$error.text(e.message);
5153
console.error(e);
5254
}
5355
});
@@ -64,16 +66,16 @@ $(function(){
6466
var dt = e.originalEvent.dataTransfer;
6567
var files;
6668
if(dt && (files=dt.files) && files.length){
67-
console.debug("dropped files: ",files);
69+
//console.debug("dropped files: ",files);
6870
var i=0;
6971
var next = function(){
7072
var file = files[i++];
7173
if(!file){return;}
72-
console.debug(i,'out of',files.length,':',file);
74+
//console.debug(i,'out of',files.length,':',file);
7375

7476
var reader = new FileReader();
7577
reader.onload = function(e){
76-
var $img = $('<img>').appendTo($results);
78+
var $img = $('<img class="frame animated flipInY"/>').appendTo($frames);
7779
$img.attr('src',reader.result);
7880
$img.on('load',function(e){
7981
var img = $img[0];
@@ -85,23 +87,12 @@ $(function(){
8587
});
8688
};
8789
reader.onerror = function(e){
90+
$error.text(e.message);
8891
console.error(reader.result,e);
8992
};
9093
reader.readAsDataURL(file);
9194
};
9295
next();
93-
/*
94-
dt.files.forEach(function(i,file,files){
95-
console.log(i,file,files);
96-
97-
var reader = new FileReader();
98-
reader.onload = function(e){
99-
var $img = $('<img>').appendTo($results);
100-
$img.attr('src',reader.result);
101-
102-
gif.addFrame($img.get(0));
103-
};
104-
});*/
10596
}
10697
});
10798
});

index.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
<head>
44
<title>GIF Maker</title>
55
<link rel="stylesheet" type="text/css" href="app.css">
6+
<link rel="stylesheet" type="text/css" href="animate-custom.css">
67
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
78
<script src="gif.js"></script>
89
<script src="app.js"></script>
910
</head>
1011
<body>
1112
Drag and drop images anywhere to add frames.
1213
<section id="frames"></section>
13-
<button id="done">Done</button>
14+
<section id="go">
15+
<button id="done">Done</button>
16+
<span id="error"></span>
17+
</section>
1418
<section id="results"></section>
1519
<footer>
1620
This app uses <a href="https://github.com/jnordberg/gif.js">gif.js</a> by Johan Nordberg

0 commit comments

Comments
 (0)