0

I have a Bootstrap navigation bar that is fixed in position and has a transparent background. Let's say it's 80px tall. Then in the body of my document I have an img that's around 1000px tall (the image is just set to width 100%). So what I want to happen is when the user scrolls up, the image scrolls up as it should, but then when it hits the point that only 80px of the image is showing, the image becomes fixed in position and remains the background of the navigation bar.

I'm not sure if it would be better to keep my current code:

<nav>

</nav>
<img>

Or if it would be better to make the navigation bar really tall with the image as a background and shrink the navigation bar and change the image offset as the scroll occurs.

Alex
  • 724
  • 1
  • 9
  • 24

1 Answers1

0

I think i got it the way you want.

$(window).scroll(function() { 
if ($(this).scrollTop()> 500 ) { 
$('#menu').css('background-image', 'url(' +    "https:
//vincentloy.files.wordpress.com/2010/09/
tragic-1-city-skyscrapers.jpg" + ')');
$('#menu').css('position', 'fixed');

}  else { 
$('#menu').css('background', 'transparent');
$('#menu').css('position', 'relative');
};
});

http://codepen.io/damianocel/pen/ZbVNvq

Let me know if I have got this right, cheers.

damiano celent
  • 721
  • 6
  • 12
  • That almost works, but I wanted the Image to be parallax rather than just jumping into position and unfortunately, it's causing way too much lag – Alex Nov 16 '15 at 23:05