Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Using bg-image contain + bg-attachment fixed Reply To: Using bg-image contain + bg-attachment fixed

#208599
modiophile
Participant

Partial solution found, http://jsfiddle.net/13cf7hd1/

The problem with this snippet is that its geared for background-size: cover and not for contain

$(window).scroll(function() {
  var scrolledY = $(window).scrollTop();
  $('#container').css('background-position', 'center ' + ((scrolledY)) + 'px');
});

If you resize the browser window and refresh you’ll see that the background image loads at the bottom correctly, however once you scroll even 1px it quick jumps up farther than the calculated scrolledY. What’s up with that?