-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom.pug
454 lines (412 loc) · 14.3 KB
/
dom.pug
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
//- The whole website is presented as a single pug file. 400 or so lines!
head
title dom.fyi
//- Using jQuery, a custom font and a few display libraries for doing the 'watch me code this site' stuff.
//- I would use React these days.
script(src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js")
script(src="//use.edgefonts.net/passion-one.js")
link(href="prism.css" rel="stylesheet")
script(src="prism.js")
script(src="lettering.js")
script(src="scrollControl.js")
meta(name="viewport" content="width=device-width, user-scalable=no")
script
:coffee-script
$ ->
total_frames = 37
px_per_frame = 8
section_timeout_delay = 300
# Set the image animation logic
frame = 0
setFrame = ->
if ($ 'header').hasClass('repress_scroll')
return $('.image').css 'background-position-y': 0
scroll_height = document.body.scrollTop
new_frame = Math.min total_frames - 1, Math.max 0, scroll_height / px_per_frame
return if new_frame is frame
return if !($ 'header').is(':visible')
frame = Math.ceil(new_frame)
$('.image').css 'background-position-y': "-#{frame*480}px"
$(window).scroll setFrame
# Define the demo. Start by hiding everything, show the demo code container and the images container.
demo =
start: (done) ->
disableScroll()
$('body').addClass('demo_active').fadeOut ->
$(@).children().hide().parent().show()
$('.demo, .images').fadeIn done
# Animate code being written. Accepts a code block. Uses the lettering library to break the code into induvidual letters.
code: ($pre, done) ->
rate = 1
cursor_delay_per_line = 3
timeout = no
$('blinking-cursor').remove()
$cursor = $('<span>').addClass('blinking-cursor').text '|'
$pre.fadeIn()
$pre.find('.token').lettering().find('span').hide()
$("body").animate scrollTop: $(document).height(), 400, ->
$pre.find('.token span').each (i) ->
$(@).delay(i * rate).fadeIn 1, ->
$("html, body").animate scrollTop: $(document).height(), 0
if $pre.find('.token span').length - 1 is i
$cursor.insertAfter $(@)
lines = $pre.find('.token').length
clearTimeout timeout
delay = section_timeout_delay + (cursor_delay_per_line * lines)
timeout = setTimeout done, delay
# Show all of the images splayed out into a grid.
images: ($pre, done) ->
@code $pre, ->
$("body").animate {scrollTop: 0}, 200, ->
rate = 25
frame_selection = total_frames - 2
for current_frame in [1..frame_selection]
$("body").animate {scrollTop: 0}, 0
image = "dom/#{current_frame}.jpg"
$image = $('<img>').attr 'src': image, frame: current_frame
$('.images').prepend $image
delay = (frame_selection - current_frame) * rate
$image.hide().delay(delay).fadeIn ->
if parseInt($(@).attr('frame')) is frame_selection
$('pre.init').slideUp ->
setTimeout done, section_timeout_delay
# Show the title, stack up the images and make the starting image grow to the correct size.
header: ($pre, done) ->
@code $pre, ->
$pre.slideUp()
$('header h1, header h4').hide().fadeIn 1000
$('header .image').hide()
$('header').addClass('nofont').addClass('repress_scroll').show()
$('.images img').each ->
rate = 20
current_frame = $(@).attr('frame')
if frame > 1
$(@).delay(current_frame * rate).animate marginLeft: -48, ->
if parseInt(current_frame) is total_frames - 2
$('.images img').css(marginLeft: 0).not(':last').remove()
$('.images img').animate height: 480, ->
$('header .image').show()
$('.images').empty()
$("html, body").animate scrollTop: $(document).height(), 400
setTimeout done, section_timeout_delay
# Add the custom font
font: ($pre, done) ->
@code $pre, ->
$('header').removeClass 'nofont'
$('pre.font').slideUp ->
setTimeout done, section_timeout_delay
# Demo the scrolling
animation: ($pre, done) ->
@code $pre, ->
$("body").animate {scrollTop: 30}, 400, ->
$('header').removeClass 'repress_scroll'
$("body").animate { scrollTop: 60 }, 400, ->
$("body").animate {scrollTop: 30}, 400, ->
$("body").animate {scrollTop: 60}, 400, ->
$('header').addClass 'repress_scroll'
$('pre.scroll').hide()
setTimeout done, section_timeout_delay
# Show the main body text of the page
body: ($pre, done) ->
@code $pre, ->
$('article').addClass('kill_margin').slideDown 400
$('pre.body').delay(800).slideUp 400
$('.start').addClass('disabled')
setTimeout done, 1200 + section_timeout_delay
# Reset the button
button: ($pre, done) ->
$('footer').show().find('img').css opacity: 0, margin: '0 -4px'
@code $pre, ->
$('.start').removeClass('kill_margin').slideDown()
$('pre.demo_code').slideUp ->
$('.start').removeClass 'disabled'
setTimeout done, section_timeout_delay
# Show the footer
footer: ($pre, done) ->
@code $pre, ->
rate = 200
$('footer img').each (i) ->
$(@).delay(i * rate).animate {opacity: 1}, 600
$('pre.footer').delay(1200).slideUp 800, done
# Scroll the page to the top and reset everything
end: ->
$("html, body").delay(200).animate { scrollTop: 0 }, 1000, ->
enableScroll()
$('body').removeClass 'demo_active'
$('header').removeClass 'repress_scroll'
$('.recursive').removeClass 'recursive'
# Bind this to the button click
$('.start').click ->
demo.start ->
demo.images $('pre.init'), ->
demo.header $('pre.header'), ->
demo.font $('pre.font'), ->
demo.animation $('pre.scroll'), ->
demo.body $('pre.body'), ->
demo.button $('pre.demo_code'), ->
demo.footer $('pre.footer'), ->
demo.end()
//- Stylus for the CSS logic.
style
:stylus
body
font-family "Gill Sans MT", "Gill Sans", "Gill Sans Std", Verdana, sans-serif
width 360px
margin 8px auto 8px auto
&.demo_active
pointer-events none !important
h4
letter-spacing 2px
margin 1px 0 0 0
font-weight normal
font-size 1.15em
.jobtitle
font-size 1.3em;
text-transform uppercase
margin 6 0 0 0
a:link, a:any-link
color red !important
text-decoration none
header
margin 16px auto 0 auto
text-align right
&.nofont
h1, h4
font-family serif !important
.image
height 480px
background url('dom/full.jpg')
h1
font-family passion-one, sans-serif
font-size 2.2em
margin 16px 0 3px 0
line-height 0.5em
article
color #4a4a4a
padding 32px 62px 42px 62px
margin-bottom 18px
background #efefef
font-size 1.2em
line-height 1.7em
letter-spacing 1px
&:first-of-type
margin-top 48px
.recursive
display none
.start
padding 16 32
background #222
color white
cursor pointer
font-weight bold
font-family passion-one, sans-serif
text-align center
vertical-align top
display inline-block
font-size 1.4em
border-radius 8px
&.kill_margin
margin-bottom 0px
&.disabled
background #747474
pointer-events none
footer
display inline-block
text-align center
margin 0
margin-right 11px
width 104px
margin-bottom 8px
img
margin 0 -4px
.images
img
display inline-block
height 60px
margin 3px
:first-child
z-index 2
.demo
display none
code, pre
word-wrap break-word
font-size 0.9em
.prism-show-language
display none
pre
display none
background none
pre.scroll, pre.body
margin-top 32px
.blinking-cursor
color #2e3d48
font-size 1.6em
line-height 1em
margin-left -2px
vertical-align bottom
display inline-block
animation 1.5s blink step-end infinite
@keyframes blink {
from, to { opacity: 0; }
50% { opacity: 1; }
}
//- The actual page layout
body
.images
header
.image
h1 DOM VINYARD
h4.jobtitle Designer & Developer
article
section
p I ❤ simple, minimal information design.
p I've designed cool stuff for the NHS, AXA, the RAF and Oxford Nanopore. 💻🔥
footer
a(href="mailto:[email protected]"): img(src="icons/mail.png")
a(href="https://github.com/DomVinyard/domvinyard.com/blob/master/dom.pug")
img(src="icons/github.png")
.start
h4 WATCH ME CODE
//- Watch me code this site
.demo
pre.init
code(class="language-coffeescript")
|# HELLO WORLD
|
|# fire up a node server
|app = require('express')()
|app.listen process.env.PORT
|app.use express.static 'resources'
|app.set 'view engine', 'pug'
|app.get '/', (req, res) -> res.render 'dom'
|
|# Preload the images
|do preload = (frame = 1) ->
| if frame < total_frames
| img = new Image()
| img.src = "/dom/#{frame}.jpg"
| img.onload = -> preload frame + 1
code(class="language-jade")
|
|
|//- Client. Import jQuery
|// - (I'd use react now)
|script(src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js")
|
pre.header
code(class="language-jade")
|//- HEADER (NAME AND JOB)
|
|//- Build template
|header
| img(src="/dom/1.jpg")
| h1 DOM VINYARD
| h4 Designer & Developer
|
code(class="language-stylus")
|
|// Apply styling
|header
| margin 0 auto 68px auto
| text-align right
| img
| height 480px
| h1
| font-size 2.2em
| margin 10px 0 2px 0
| line-height: 0.5em
| h4
| letter-spacing 2px
| margin 6px 0 0 0
| font-size 1.1em
pre.font
code(class="language-jade")
|//- CUSTOM FONT
|
|//- Import
|script(src="//use.edgefonts.net/passion-one.js")
|
code(class="language-stylus")
|
|//- Apply styling
|h1
| font-family passion-one
|h4
| font-family "Gill Sans MT"
pre.scroll: code(class="language-coffeescript")
|# IMAGE CHANGE ON SCROLL (FRIENDLY)
|
|# Set the framerate
|total_frames = 37
|px_per_frame = 9
|
|# Look for scrolling
|$(window).scroll ->
| scroll_height = $(window).scrollTop()
| frame = scroll_height / px_per_frame
|
| # Every 9px down is a new frame
| frame = Math.max 1, Math.ceil frame
| frame = Math.min total_frames, frame
| image = '/dom/'+frame+'.jpg'
|
| # Set the image
| $('header img').attr 'src': image
pre.body
code(class="language-jade")
|//- PAGE CONTENT (CASUAL)
|
|//- Main Text
|article
| section <main_text>
|
|//- Button to start demo
|.start
| h4 WATCH ME CODE THIS SITE
|
code(class="language-stylus")
|
|// Apply styling
|article
| color #222
| padding 16px 32px
| margin 12px 0
| background #eee
|.start
| padding 16px 0
| background #222
| color white
| font-weight bold
| font-family: passion-one
| text-align center
| font-size 1.4em
pre.demo_code
code(class="language-coffeescript")
|# RESET THE BUTTON (META)
|
|# User clicks the button
|$('.start').click ->
| demo.start ->
| demo.images $('.init'), ->
| demo.header $('.header'), ->
| demo.font $('.font'), ->
| demo.animation $('.scroll'), ->
| demo.body $('.body'), ->
| demo.button $('.code'), ->
| demo.footer $('.foot'), ->
| demo.end()
code(class="language-jade")
|
|
|//- Prism makes code look pretty
|link(href="/prism.css" rel="stylesheet")
|script(src="/prism.js")
pre.footer: code(class="language-jade")
|//- CONTACT
|
|//- Template
|footer
| a(href="mailto:[email protected]")
| img(src="icons/mail.png")
| a(href="https://twitter.com/_DomVinyard")
| img(target="_blank" src="icons/twitter.png")