JSFiddle - React, Tailwind, and code Playground
by Riskbreaker
HTML
<img src="http://psyarts.com/wp-content/uploads/2012/09/inception06.jpg" id="time" alt="">
CSS
body {padding: 0; margin:0}
#time {position: fixed; top: 0; left: 0; }
.bgheight { height: 100%; }
.bgwidth { width: 100%; }
JavaScript
$(function() {
var theWindow = $(window),
$bg = $("#time"),
aspectRatio = $bg.width() / $bg.height();
function resizeBg() {
if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
$bg
.removeClass()
.addClass('bgheight');
} else {
$bg
.removeClass()
.addClass('bgwidth');
}
}
theWindow.resize(function() {
resizeBg();
}).trigger("resize");
});