Reputation: 105
I tried to make parallax effect on tag. but it is not working. http://prntscr.com/rbq4ha I need to make the image as parallax like the linked image. please help me.
Upvotes: 1
Views: 1323
Reputation: 1229
Use a container element and add a background image to the container with a specific height. Then use the background-attachment: fixed
to create the actual parallax effect. The other background properties are used to center and scale the image perfectly/
Here is an example:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.parallax {
/* The image used */
background-image: url("https://miro.medium.com/max/2046/1*ZJuc_2TsDElu6Gtg_KxiEg.png");
/* Set a specific height */
min-height: 500px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<p>Scroll Up and Down this page to see the parallax scrolling effect.</p>
<div class="parallax"></div>
<div style="height:1000px;background-color:red;font-size:36px">
Scroll Up and Down this page to see the parallax scrolling effect.
This div is just here to enable scrolling.
Tip: Try to remove the background-attachment property to remove the scrolling effect.
</div>
</body>
</html>
Here is an easy tutorial how to create parallax scrolling.
Upvotes: 1