Parallax is a 3d effect used in various websites to make webpages attractive . In this effect, as we scroll, the background of the webpages moves at different speed than the foreground making it look brilliant to the eyes.
These websites show the parallax effect brilliantly-
This effect is a great visual but an easy method to implement with the help of CSS.
First, let us understand what is happening in the given examples.
The effect is created because the image in the background is kept fixed with no movement but other images are moving . This simple technique makes this effect look brilliant.
Now let us see the implementation of this effect using CSS-
This property is used to determine whether a background image is fixed or scroll with the page.
Syntax : background-attachment: scroll/fixed/local;
This property determines the starting position of the background image.
Syntax : background-position: value;
This property determines whether a background image will repeat or not and if repeated , how will it be repeated.
Syntax : background-repeat: repeat/repeat-x/repeat-y/no-repeat;
repeat – The background image will be repeated both vertically and horizontally.
repeat-x – The background image will be repeated only horizontally.
repeat-y – The background image will be repeated only vertically.
no-repeat – The background-image will not be repeated.
This property determines the size of the background image.
Syntax : background-size: auto/length/cover/contain/;
auto – Default value.
length – Sets the width and height of the background image.
percentage – Sets the width and height of the background image in percent of the container element.
cover – Scale the background image to be as large as possible so that the background area is completely covered by the background image.
contain – Scale the image to the largest size such that both its width and its height can fit inside the content area.
Note that This parallax effect does not always work with mobiles and tablets, soyou need to turn off the effect using media queries.
This article is contributed by Ayush Saxena. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- HTML5 Game Development | Infinitely Scrolling Background
- CSS | Shadow Effect
- jQuery | Effect fadeOut() Method
- jQuery | Effect show() Method
- How to change opacity while scrolling the page?
- How to create fade-in effect on page load using CSS ?
- Node.js Events
- Include Bootstrap in AngularJS using ng-bootstrap
- How to determine the content of HTML elements overflow or not ?
- How to Add and Remove multiple classes in jQuery ?
- AngularJS | ng-jq Directive