-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
74 lines (52 loc) · 2.3 KB
/
javascript.js
File metadata and controls
74 lines (52 loc) · 2.3 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
$(function() {
// IE detect
function iedetect(v) {
var r = RegExp('msie' + (!isNaN(v) ? ('\\s' + v) : ''), 'i');
return r.test(navigator.userAgent);
}
// For mobile screens, just show an image called 'poster.jpg'. Mobile
// screens don't support autoplaying videos, or for IE.
if(screen.width < 800 || iedetect(8) || iedetect(7) || 'ontouchstart' in window) {
(adjSize = function() { // Create function called adjSize
$width = $(window).width(); // Width of the screen
$height = $(window).height(); // Height of the screen
// Resize image accordingly
$('#container').css({
'background-image' : 'url(poster.jpg)',
'background-size' : 'cover',
'width' : $width+'px',
'height' : $height+'px'
});
// Hide video
$('video').hide();
})(); // Run instantly
// Run on resize too
$(window).resize(adjSize);
}
else {
// Wait until the video meta data has loaded
$('#container video').on('loadedmetadata', function() {
var $width, $height, // Width and height of screen
$vidwidth = this.videoWidth, // Width of video (actual width)
$vidheight = this.videoHeight, // Height of video (actual height)
$aspectRatio = $vidwidth / $vidheight; // The ratio the video's height and width are in
(adjSize = function() { // Create function called adjSize
$width = $(window).width(); // Width of the screen
$height = $(window).height(); // Height of the screen
$boxRatio = $width / $height; // The ratio the screen is in
$adjRatio = $aspectRatio / $boxRatio; // The ratio of the video divided by the screen size
// Set the container to be the width and height of the screen
$('#container').css({'width' : $width+'px', 'height' : $height+'px'});
if($boxRatio < $aspectRatio) { // If the screen ratio is less than the aspect ratio..
// Set the width of the video to the screen size multiplied by $adjRatio
$vid = $('#container video').css({'width' : $width*$adjRatio+'px'});
} else {
// Else just set the video to the width of the screen/container
$vid = $('#container video').css({'width' : $width+'px'});
}
})(); // Run function immediately
// Run function also on window resize.
$(window).resize(adjSize);
});
}
});