JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://malsup.github.com/jquery.cycle2.js"></script>
<div id="background" class="cycle-slideshow" data-cycle-fx="scrollHorz" data-cycle-timeout="2000" data-cycle-slides="> div">
<div style="background:#fcc">
<img src="http://stoptraining.me/staged/IMG_1402.jpg">
</div>
<div style="background:#cfc">
<img src="http://stoptraining.me/staged/IMG_1403.jpg">
</div>
</div>
<div class="center">
<div id="log"></div>
<div id="text" class="cycle-slideshow" data-cycle-fx="fade" data-cycle-timeout="2000" data-cycle-slides="> div">
<div>
<h2>Title</h2>
<p>Lorem ipsum dolor ...</p>
</div>
<div>
<p>Mel eu pertinax ...</p>
</div>
<div>
<p>Utinam electram pertinacia ...</p>
</div>
</div>
</div>
CSS
/* Eric Meyer's Reset Reloaded */
/* http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ */
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
/* remember to define focus styles! */
:focus {
outline: 0;
}
/* remember to highlight inserts somehow! */
ins {
text-decoration: none;
}
del {
text-decoration: line-through;
}
/* tables still need 'cellspacing="0"' in the markup */
table {
border-collapse: collapse;
border-spacing: 0;
}
body, html {
background: red;
padding:0;
margin:0;
height:auto;
width: 100%;
}
#background {
position: fixed;
width: 100%;
height: 100%;
z-index: 99;
overflow: hidden;
}
#background div {
width: 100%;
height: 100%;
background-size:cover;
overflow: hidden;
}
#text {
position: relative;
text-align: center;
z-index: 99;
}
.center {
background: white;
padding: 200px 0 0 0;
width: 400px;
overflow: auto;
min-height: 1000px;
margin: auto;
z-index: 9999;
position: relative;
text-align: center;
}
#background div img.wider {
width: 100%;
height: auto;
}
#background div img.higher {
width: auto;
height: 100%;
}
JavaScript
var imgWidth = 1600;
var imgHeight = 1067;
var imgRatio = imgWidth / imgHeight;
$(ResizeBackground); // call on initialize
$(window).resize(ResizeBackground); // and on resize
function ResizeBackground() {
var div = $('#background');
var divWidth = div.width();
var divHeight = div.height();
if (divWidth / divHeight > imgRatio) {
div.find('img').removeClass('higher').addClass('wider');
} else {
div.find('img').removeClass('wider').addClass('higher');
}
}