-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtm.fullscreen.js
44 lines (34 loc) · 927 Bytes
/
tm.fullscreen.js
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
/* Thomas Mulloy, thomasmulloy.com */
/* video as fullscreen background, maintained aspect ratio, centered */
(function($){
$.fn.fullscreen = function(){
var $el = this,
w = $el.width(),
h = $el.height(),
ar = w/h,
scr_w,
scr_h,
scr_ar;
function scale(){
scr_w = $(window).width();
scr_h = $(window).height();
scr_ar = scr_w/scr_h;
var tmp_h, tmp_w;
if(scr_ar < ar){
tmp_w = Math.ceil(scr_h*ar);
$el.height(scr_h).width(tmp_w).css({
'margin-top': 0,
'margin-left': -Math.floor((tmp_w-scr_w)/2)
});
}else{
tmp_h = Math.ceil(scr_w/ar);
$el.height(tmp_h).width(scr_w).css({
'margin-top':-Math.floor((tmp_h-scr_h)/2),
'margin-left': 0
});
}
}
$(window).on('resize.fullscreen', scale).trigger('resize');
return false;
};
}(jQuery));