4

I'm trying to get a background image to start and stay in a fixed position, but only until the rest of the 'content' of the page is finished, at which point the full image is displayed.

I'm working on a purely CSS solution. I should note that the image is larger than most (laptop) screens.

Specifically, here's the code that I've been using:

body {
  background:$bgcolor;
  background-image:url('http://i.imgur.com/cIGSehG.jpg');
  background-repeat:no-repeat;
  background-position:0px 72px;
  background-attachment:fixed;
  margin:0;
  ...
}

The image that I'm using is given in the url():

Background image from snippet

The effect that I'm looking for is basically the image will display only about the top 10% of the grass hill while you're looking at most of the page, but if you finally scroll all the way down past all the page content, the remaining 90% of the grass hill will be shown.

I couldn't find this anywhere, but I may have just been using poor search terms since I'm not so familiar with the lingo.

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
Free
  • 663
  • 9
  • 13

1 Answers1

1

Well, this was one jiggy nut! I did come up with a not so stable trick to achieve this. I don't have time to develop it any more right now, but perhaps it might be a working concept.

Main contept

By providing a large and empty footer area that the user is likely to hover when reaching the bottom of the page, we use a sibling selector to change the position of its sibling element containing the background:

#footer:hover ~ #background {
    background-position: center bottom;
}

Along with a few quirks (which ought to be improved) we can achieve a parallax effect.

Go Fiddle

Check out this JFiddle (in Chrome) to see and play with it.

Alexander Wallin
  • 1,394
  • 10
  • 22