It's actually super simple. The nav and content containers are in the flow. The content has a margin-top
to separate it from the nav. Then the background image is set to position: fixed
, and on scroll is offset by a percentage of the scroll position (eg, 30%).
You don't need any libraries, but jQuery makes it easier. Considering stellar.js requires jQuery, I assume you don't have a problem using it. In which case, the following code is enough to get it working for you:
$(window).on('scroll', function() {
$('#background').css('margin-top', $(window).scrollTop() * -.3);
});
Here is a jsFiddle of the entire thing in action: http://jsfiddle.net/9gK9z/1/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…