-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarwarscrawl.js
More file actions
65 lines (55 loc) · 1.53 KB
/
starwarscrawl.js
File metadata and controls
65 lines (55 loc) · 1.53 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
/*
* http://timpietrusky.com/star-wars-opening-crawl-from-1977
*
* 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() {
//await new Promise(resolve => setTimeout(resolve, 15000));
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'
});