What is parallax
Parallax is an effect where the background layer or image in this case, is moved at a different speed than the front layer while scrolling.
Parallax design is a popular technique in modern webdesign. There are two approaches to this effect: CSS and JS. Both are really easy. So here we go
CSS Approach
For your background image, you need to make the background-attachment property fixed. This will set whether the background image is fixed or scrolls with the rest of the page.
1 | <style> |
Here’s a demo of how the site will work. My Github Demo
JS Approach
In your html section add data-type and data-speed attribute. The speed will adjust the speed of how the background move.
Markup1
2
3
4
5
6
7<section id="home" data-type="background" data-speed="10">
<article>I am absolute positioned</article>
</section>
<section id="about" data-type="background" data-speed="10">
<article>Simple Parallax Scroll</article>
</section>
1 | #home { |
1 | $(document).ready(function(){ |
The concept of this code is illusrated in this image.