Fixed, scrolling background images. Fixed, scrolling background images Fixed html background

💖 Do you like it? Share the link with your friends

This short lesson will be about how to create a beautiful fixed background on your website (or on a one-page page) that will smoothly flow from one image to another as the user scrolls the page. CSS has this property background-attachment: fixed , which allows you to fix background image. That is, when you scroll the page, it will not scroll with the page. But there is no property in CSS that would allow us to change images when scrolling, so we will use Javascript.

Fixed background for the site

You may not understand what I’m writing about, so watch the demo and you will see this beautiful effect for yourself:

Download

How to make a changing background for a website?

HTML

We'll start by defining the HTML structure of the page for which we're making this effect:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 <div id = "cbp-fbscroller" class = "cbp-fbscroller" >

In the tag