I'm trying to solve a problem in which I need a background image to stay in place when the address bar and the content below scroll upwards.
The image takes up 90% of the view height,I've used JS to stop this resizing and jumping when the address bar hides, but the image will still move upwards with the body of my site when the address bar hides.
I'm aiming to have the image fixed in place no matter what, so that as you begin scrolling, the content near the bottom of the screen and the address bar scroll up simulatneously, and the image remains in the same spot. It's simple enough until the viewport starts changing!
Preventing the address bar from hiding isn't an option.
Here's a representation of what I'm trying to achieve, featuring my dog
Dog stays still when content scrolls and address bar hides = good girl
HTML
<body>
<img class="dog" src="..."/>
<div class="content">
<p>Some stuff</p>
</div>
</body>
CSS
.dog {
position: fixed;
left: 50%;
}
.content {
position: relative;
}
I'm thinking maybe I could position the image relative to the bottom of the view port and have it overflowing under the address bar but im not really sure how to achieve this. I'm going to continue attempting this now but it will take me a long time to figure out so if anyone can give me some pointers or if there's another approach to this I'd really appreciate hearing it!
Thank you