JSDM

HTML

 
1
    <header>
2
      <h1>Second Cube</h1>
3
      <p>An experiment on infinite sequences and CSS animations.</p>
4
      <p>Based on <a href="http://ffffound.com/image/15cca3c0766a634da538fb4bc8b23e2f5a4fe8a7">this image</a> from ffffound.</p>
5
    </header>
6
    <div id="viewport">
7
      <div id="tower">
8
        <div id="cubes"></div>
9
      </div>
10
    </div>
11
<script type="text/template" id="face">
12
<svg
13
  x="0px" y="0px"
14
  width="<%= size %>px"
15
  height="<%= size %>px"
16
  viewBox="0 0 <%= size %> <%= size %>"
17
  class="face <%= position %>"
18
  style="bottom: <%= bottom %>px;"
19
  id="<%= id %>"
20
  >
21
<g class="background">
22
  <rect width="<%= size %>" height="<%= size %>"/>
23
</g>
24
<g class="corners">
25
  <g>
26
    <polygon points="<%= points.tr %>"/>
27
    <polygon class="tl" points="<%= points.tl %>"/>
28
    <polygon points="<%= points.bl %>"/>
29
    <polygon points="<%= points.br %>"/>
30
  </g>
31
</g>
32
<g class="cross">
33
  <polygon points="<%= points.cross %>"/>
34
</g>
35
</svg>
36
</script>

CSS

x
 
1
body {
2
  background-color: black;
3
  color: #cccccc;
4
}
5
a {
6
  color: #333333;
7
  text-decoration: none;
8
}
9
a:hover {
10
  text-decoration: underline;
11
}
12
header {
13
  margin: 30px;
14
  position: relative;
15
  z-index: 100;
16
  max-width: 270px;
17
}
18
@media (max-width: 570px) {
19
  header {
20
    margin: 15px;
21
    max-width: 160px;
22
  }
23
  #cubes {
24
    transform: translate3d(0, 0, -500px) rotatey(45deg);
25
  }
26
}
27
.animation-defaults {
28
  animation-duration: 0.5s;
29
  animation-fill-mode: forwards;
30
  animation-timing-function: linear;
31
}
32
#viewport {
33
  position: absolute;
34
  left: 0;
35
  top: 0;
36
  width: 100%;
37
  height: 100%;
38
  perspective: 500px;
39
  overflow: hidden;
40
}
41
#tower {
42
  width: 100%;
43
  height: 100%;
44
  top: 0;
45
  left: 0;
46
  transition: transform 2.5s linear;
47
  transform-style: preserve-3d;
48
}
49
#cubes {
50
  transform-style: preserve-3d;
51
  width: 100%;
52
  height: 100%;
53
  top: 0;
54
  left: 0;
55
  perspective-origin: 50% 100%;
56
  transform: translate3d(0, -100px, -300px) rotatey(45deg);
57
}
58
.face {
59
  position: absolute;
60
  animation-duration: 0.5s;
61
  animation-fill-mode: forwards;
62
  animation-timing-function: linear;
63
  bottom: 0;
64
  left: 50%;
65
  margin-left: -100px;
66
}
67
.face .background rect {
68
  fill-opacity: 0.1;
69
  fill: #000000;
70
}
71
.face .corners polygon,
72
.face .cross polygon {
73
  fill: #F40;
74
}
75
.face.floor {
76
  transform: translatey(200px) translatez(100px);
77
  transform-origin: 0 0;
78
  animation-name: floor-animation;
79
}
80
.face.left {
81
  transform: translatex(-100px) rotatey(-90deg) rotatex(90deg);
82
  transform-origin: 100px 200px;
83
  animation-name: left-animation;
84
}
85
.face.back {
86
  transform: translatex(-200px) translatez(-100px) rotatey(90deg);
87
  transform-origin: 200px 0;
88
  animation-name: back-animation;
89
}
90
.face.right {
91
  transform: translatez(-100px);
92
  transform-origin: 200px 0;
93
  animation-name: right-animation;
94
}
95
.face.front {
96
  transform: translatez(100px) rotatey(-90deg);
97
  transform-origin: 200px 0;
98
  animation-name: front-animation;
99
}
100
@keyframes floor-animation {
101
  from {
102
    transform: translatey(200px) translatez(100px);
103
  background:  
104
     -webkit-radial-gradient(50% 0, circle, 
105
         rgba(255,0,110,.5), rgba(255,0,110,0) 70.71%), 
106
     -webkit-radial-gradient(6.7% 75%, circle, 
107
         rgba(110,0,255,.5), rgba(110,0,255,0) 70.71%), 
108
     -webkit-radial-gradient(93.3% 75%, circle, 
109
         rgba(0,255,110,.5), rgba(0,255,110,0) 70.71%);
110
  background:  
111
    radial-gradient(circle at 50% 0, 
112
         rgba(255,0,110,.9), rgba(255,0,110,0) 70.71%), 
113
    radial-gradient(circle at 6.7% 75%, 
114
         rgba(110,0,255,.9), rgba(110,0,255,0) 70.71%), 
115
    radial-gradient(circle at 93.3% 75%, 
116
         rgba(0,255,110,.9), rgba(0,255,110,0) 70.71%); 
117
118
119
   }
120
  to {
121
    transform: translatey(200px) translatez(100px) rotatex(-90deg);
122
123
  background:  
124
     -webkit-radial-gradient(50% 0, circle, 
125
         rgba(255,0,110,.5), rgba(255,0,110,0) 70.71%), 
126
     -webkit-radial-gradient(6.7% 75%, circle, 
127
         rgba(110,0,255,.5), rgba(110,0,255,0) 70.71%), 
128
     -webkit-radial-gradient(93.3% 75%, circle, 
129
         rgba(0,255,110,.5), rgba(0,255,110,0) 70.71%);
130
  background:  
131
    radial-gradient(circle at 50% 0, 
132
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
133
    radial-gradient(circle at 6.7% 75%, 
134
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
135
    radial-gradient(circle at 93.3% 75%, 
136
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%); 
137
}
138
}
139
@keyframes left-animation {
140
  from {
141
    transform: translatex(-100px) rotatey(-90deg) rotatex(90deg);
142
/*  background:#FC6; */
143
  background: /* older syntax */
144
     -webkit-radial-gradient(50% 0, circle, 
145
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
146
     -webkit-radial-gradient(6.7% 75%, circle, 
147
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
148
     -webkit-radial-gradient(93.3% 75%, circle, 
149
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
150
  background: /* newest syntax */
151
    radial-gradient(circle at 50% 0, 
152
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
153
    radial-gradient(circle at 6.7% 75%, 
154
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
155
    radial-gradient(circle at 93.3% 75%, 
156
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%); 
157
  }
158
  to {
159
    transform: translatex(-100px) rotatey(-90deg) rotatex(0deg);
160
/*  background:#FC6; */
161
  background: /* older syntax */
162
     -webkit-radial-gradient(50% 0, circle, 
163
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
164
     -webkit-radial-gradient(6.7% 75%, circle, 
165
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
166
     -webkit-radial-gradient(93.3% 75%, circle, 
167
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
168
  background: /* newest syntax */
169
    radial-gradient(circle at 50% 0, 
170
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
171
    radial-gradient(circle at 6.7% 75%, 
172
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
173
    radial-gradient(circle at 93.3% 75%, 
174
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);  
175
  }
176
}
177
@keyframes back-animation {
178
  from {
179
    transform: translatex(-200px) translatez(-100px) rotatey(90deg);
180
/*  background:#F60;*/
181
  background: /* older syntax */
182
     -webkit-radial-gradient(50% 0, circle, 
183
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
184
     -webkit-radial-gradient(6.7% 75%, circle, 
185
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
186
     -webkit-radial-gradient(93.3% 75%, circle, 
187
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
188
  background: /* newest syntax */
189
    radial-gradient(circle at 50% 0, 
190
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
191
    radial-gradient(circle at 6.7% 75%, 
192
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
193
    radial-gradient(circle at 93.3% 75%, 
194
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
195
      opacity:.6; 
196
  }
197
  to {
198
    transform: translatex(-200px) translatez(-100px) rotatey(180deg);
199
/*  background:#F60;*/
200
  background: /* older syntax */
201
     -webkit-radial-gradient(50% 0, circle, 
202
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
203
     -webkit-radial-gradient(6.7% 75%, circle, 
204
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
205
     -webkit-radial-gradient(93.3% 75%, circle, 
206
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
207
  background: /* newest syntax */
208
    radial-gradient(circle at 50% 0, 
209
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
210
    radial-gradient(circle at 6.7% 75%, 
211
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
212
    radial-gradient(circle at 93.3% 75%, 
213
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
214
      opacity:.6;   }
215
}
216
@keyframes right-animation {
217
  from {
218
    transform: translatez(-100px);
219
/*  background:#FFC;*/
220
  background: /* older syntax */
221
     -webkit-radial-gradient(50% 0, circle, 
222
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
223
     -webkit-radial-gradient(6.7% 75%, circle, 
224
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
225
     -webkit-radial-gradient(93.3% 75%, circle, 
226
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
227
  background: /* newest syntax */
228
    radial-gradient(circle at 50% 0, 
229
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
230
    radial-gradient(circle at 6.7% 75%, 
231
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
232
    radial-gradient(circle at 93.3% 75%, 
233
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
234
      opacity:.6;  
235
  }
236
  to {
237
    transform: translatez(-100px) rotatey(90deg);
238
/*  background:#FFC;*/
239
  background: /* older syntax */
240
     -webkit-radial-gradient(50% 0, circle, 
241
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
242
     -webkit-radial-gradient(6.7% 75%, circle, 
243
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
244
     -webkit-radial-gradient(93.3% 75%, circle, 
245
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
246
  background: /* newest syntax */
247
    radial-gradient(circle at 50% 0, 
248
         rgba(255,0,0,.5), rgba(255,0,0,0) 70.71%), 
249
    radial-gradient(circle at 6.7% 75%, 
250
         rgba(0,0,255,.5), rgba(0,0,255,0) 70.71%), 
251
    radial-gradient(circle at 93.3% 75%, 
252
         rgba(0,255,0,.5), rgba(0,255,0,0) 70.71%);
253
      opacity:.6;  
254
}
255
}
256
@keyframes front-animation {
257
  from {
258
    transform: translatez(100px) rotatey(-90deg);
259
background:url(www.biowellinc.com/d/diamondsml2.png) no-repeat 0px -150px;
260
opacity:1.0;      
261
} 
262
  
263
  to {
264
    transform: translatez(100px) rotatey(0deg);
265
background:url(http://www.biowellinc.com/d/diamondsml2.png) no-repeat 0px -150px;
266
opacity:1.0;      
267
}
268
}
269
#codepen-footer,#codepen-footer *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}#codepen-footer{position:fixed;bottom:0;left:0;width:100%;padding:0 10px;height:30px;color:#eeeeee;background-color:#505050;background:-webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #505050), color-stop(100%, #383838));background:-webkit-linear-gradient(#505050,#383838);background:-moz-linear-gradient(#505050,#383838);background:-o-linear-gradient(#505050,#383838);background:linear-gradient(#505050,#383838);border-top:1px solid #000;border-bottom:1px solid #000;box-shadow:inset 0 1px 0 #6e6e6e,0 2px 2px rgba(0,0,0,0.4);font:12px/30px "Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif;line-height:30px}#codepen-footer a{color:#a7a7a7;text-decoration:none}#codepen-footer a:hover{color:white}#footer-right{position:absolute;right:5px;top:0}@media (max-width: 600px){#footer-right{display:none}}#bs-button{padding:1px 6px 2px 19px;background:url(/images/browserstack.png),-webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #fff4d1), color-stop(100%, #c9b67b));background:url(/images/browserstack.png),-webkit-linear-gradient(#fff4d1,#c9b67b);background:url(/images/browserstack.png),-moz-linear-gradient(#fff4d1,#c9b67b);background:url(/images/browserstack.png),-o-linear-gradient(#fff4d1,#c9b67b);background:url(/images/browserstack.png),linear-gradient(#fff4d1,#c9b67b);background-position:4px center,center center;background-repeat:no-repeat;background-size:12px 12px,cover;border:0;font:11px "Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif;border-radius:5px}#bs-button:hover{background-color:#fff4d1;background-position:4px center,center center;background-repeat:no-repeat;background-size:12px 12px,cover}
270
271
 
272
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

xxxxxxxxxx
130
 
1
$(function() {
2
3
  //--------------------------------------------------------------------------
4
  //
5
  // Framework
6
  //
7
  //--------------------------------------------------------------------------
8
9
  var points = {
10
    tr: [[0.83, 0], [0.83,0.01], [0.99,0.01], [0.99,0.17], [1,0.17], [1, 0]],
11
    tl: [[0.01, 0.01], [0.17,0.01], [0.17,0], [0,0], [0,0.17], [0.01, 0.17]],
12
    bl: [[0.01, 0.99], [0.01,0.83], [0,0.83], [0,1], [0.17,1], [0.17, 0.99]],
13
    br: [[0.99, 0.99], [0.83,0.99], [0.83,1], [1,1], [1,0.83], [0.99, 0.83]],
14
    cross: [
15
      [0.67, 0.50],
16
      [0.50, 0.50],
17
      [0.50, 0.33],
18
      [0.49, 0.33],
19
      [0.49, 0.50],
20
      [0.33, 0.50],
21
      [0.33, 0.51],
22
      [0.49, 0.51],
23
      [0.49, 0.67],
24
      [0.50, 0.67],
25
      [0.50, 0.51],
26
      [0.67, 0.51]
27
    ]
28
  };
29
30
  var scalePoint = function (point, scale) {
31
    return _.map(point, function (value) {
32
      return value * scale;
33
    });
34
  };
35
36
  var makeContext = function (size) {
37
    size = parseFloat(size);
38
    size = _.isNaN(size) ? 100 : size;
39
    var context = {};
40
    context.size = size;
41
    context.points = _.reduce(points, function (scaledPoints, points, property) {
42
      scaledPoints[property] = _.map(points, function (point) {
43
        return scalePoint(point, size);
44
      });
45
      return scaledPoints;
46
    }, {});
47
    return context;
48
  };
49
50
  var faceMaker = function (position, next) {
51
    return function (template, context, level) {
52
      context = _.extend({}, context, {position: position});
53
      var face = {
54
      };
55
      face.next = function (level) {
56
        return next(template, context, level);
57
      };
58
      face.render = function () {
59
        context.bottom = context.size * level;
60
        context.id = face.id();
61
        return template(context);
62
      };
63
      face.id = function () {
64
        return context.position + level;
65
      };
66
      return face;
67
    };
68
  };
69
70
  var floor = faceMaker('floor', function (t, c, l) { return left(t, c, l) });
71
  var left = faceMaker('left', function (t, c, l) { return back(t, c, l) });
72
  var back = faceMaker('back', function (t, c, l) { return right(t, c, l) });
73
  var right = faceMaker('right', function (t, c, l) { return front(t, c, l) });
74
  var front = faceMaker('front', function (t, c, l) { return floor(t, c, l) });
75
76
  //--------------------------------------------------------------------------
77
  //
78
  // App
79
  //
80
  //--------------------------------------------------------------------------
81
  
82
  var tmpl = _.template($('#face').html()),
83
      $tower = $('#tower'),
84
      $cubes = $('#cubes'),
85
      size = 200,
86
      ctx = makeContext(size),
87
      limit = 40,
88
      count = 0,
89
      level = 0,
90
      levels = [[]],
91
      face = floor(tmpl, ctx, 0)
92
      maxLevels = 4;
93
  
94
  var moveTower = function () {
95
    var distance = size / 5;
96
    var css = 'translateY(' + (distance * count) + 'px)';
97
    $tower.css('transform', css);
98
  };
99
100
  var cleanupOldLevels = function () {
101
    if (levels.length > maxLevels) {
102
      var first = levels.shift().join(',');
103
      $(first).remove();
104
    };
105
  };
106
107
  var updateLevels = function () {
108
    var l = Math.floor(count / 5);
109
    if (l !== level) {
110
      level = l;
111
      levels.push([]);
112
      cleanupOldLevels();
113
    };
114
  };
115
116
  var appendFace = function () {
117
    $cubes.append(face.render());
118
    levels[levels.length - 1].push('#' + face.id());
119
    count ++;
120
    updateLevels();
121
    moveTower();
122
    face = face.next(level);
123
  };
124
125
  $cubes.bind('webkitAnimationEnd animationend', function () {
126
    appendFace();
127
  });
128
  
129
  appendFace();
130
});
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

  1. 暂无文件
拖动文件到上面的区域或者:
加载中 ..................