-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathjavascript.html
More file actions
85 lines (75 loc) · 2.13 KB
/
Copy pathjavascript.html
File metadata and controls
85 lines (75 loc) · 2.13 KB
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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
/*
* Star Wars opening crawl from 1977
*
* I freaking love Star Wars, but could not find
* a web version of the original opening crawl from 1977.
* So I created this one.
*
* I wrote an article where I explain how this works:
* http://timpietrusky.com/star-wars-opening-crawl-from-1977
*
* Watch the Start Wars opening crawl on YouTube.
* https://www.youtube.com/watch?v=7jK-jZo6xjY
*
* Stuff I used:
* - CSS (animation, transform)
* - HTML audio (the opening theme)
* - SVG (the Star Wars logo from wikimedia.org)
* http://commons.wikimedia.org/wiki/File:Star_Wars_Logo.svg
* - JavaScript (to sync the animation/audio)
*
* Thanks to Craig Buckler for his amazing article
* which helped me to create this remake of the Star Wars opening crawl.
* http://www.sitepoint.com/css3-starwars-scrolling-text/
*
* Sound copyright by The Walt Disney Company.
*
*
* 2013 by Tim Pietrusky
* timpietrusky.com
*
*/
StarWars = (function() {
/*
* Constructor
*/
function StarWars(args) {
// Context wrapper
this.el = $(args.el);
// Audio to play the opening crawl
this.audio = this.el.find('audio').get(0);
// Start the animation
this.start = this.el.find('.start');
// The animation wrapper
this.animation = this.el.find('.animation');
// Remove animation and shows the start screen
this.reset();
// Start the animation on click
this.start.bind('click', $.proxy(function() {
this.start.hide();
this.audio.play();
this.el.append(this.animation);
}, this));
// Reset the animation and shows the start screen
$(this.audio).bind('ended', $.proxy(function() {
this.audio.currentTime = 0;
this.reset();
}, this));
}
/*
* Resets the animation and shows the start screen.
*/
StarWars.prototype.reset = function() {
this.start.show();
this.cloned = this.animation.clone(true);
this.animation.remove();
this.animation = this.cloned;
};
return StarWars;
})();
new StarWars({
el : '.starwars'
});
</script>