JSFiddle - React, Tailwind, and code Playground
HTML
<div id="background"></div>
<div id="content"></div>
CSS
#background {
/* fixed position - aways on top of the screen */
position: fixed;
top: 0;
left: 0;
/* set repeat-x so it doesn't run off */
background: url(http://dummyimage.com/3000x100/333/999.png&text=foobarfoobarfoobarfoobarfoobar) repeat-x;
/* you MUST set width and height or it won't display */
width: 100%;
height: 100px;
/* -1 to ensure it will always be in background */
z-index: -1;
}
#content{
width: 500px;
margin: 0 auto;
background: #b0b0b0;
}
JavaScript
// add some content
for(var i=0;i<50;i++)
$("#content").append('<p>some text</p>');
// event which fires on scroll
$(window).scroll(function () {
// parse the value of current background position and add window.scrollY - vertical scroll (divide this for slower background scroll)
var offset = parseInt($("#background").css("background-position-x")) + window.scrollY;
$("#background").css("background-position-x", offset + "px");
});