How do I make an image fade out but stay in place on scroll?

ctrinh

In the Adirondack template from Squarespace, there's a banner image of a purse that does this crazy thing where you scroll down and it fades out to white, but it seems to stay in the same position even as you scrolldown. It's really hard to articulate what I'm talking about, so I included an animated GIF of the image effect I'm talking about. Does anyone have any ideas about how could I go about replicating that? Thank you!

Joe Warner

What you're referring to is Parallax Scrolling there are a ton of tutorials and examples but here is a simple implementation

https://www.w3schools.com/howto/howto_css_parallax.asp

https://codepen.io/nickcil/pen/sfutl

$(window).scroll(function() {
  $(".parallax").css("opacity", 1 - $(window).scrollTop() / 350);
});
.parallax {
  /* The image used */
  background-image: url("https://images.unsplash.com/photo-1530357075171-3c4b84478ebd?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=b930fe4c342d9dcbee9e3b3939ccbe5f&auto=format&fit=crop&w=1300&q=80");
  /* 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;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How an I make a background image fade out to reveal text on hover?

I can make an div fade in onclick, but how do i make it fade out?

With SDL 2.0 in C, how do I make a rectangle fade in and out?

How do I make two images fade in/out repeatedly?

How do I make the dropdown fade in and out transition?

How do I hide or fade out an image (created with loadImage)?

How can I make fade out text

How can I make the top and bottom elements of my view controller stay in place, while the middle has elements to vertically scroll through?

In Vue.js how to make a nav fade in on scroll down event and fade out where scroll pageYOffset = 0

Javascript - make a div fade in, stay there for a time, fade out and remove it then

How would i make background image fade in?

How do I fade out images in JS?

How do I add fade in fade out to inner HTML?

How can I fade in/out an image to make effect that the screen get dark slowly?

How do I make a button stay pressed?

How do I make an image endlessly repeat scroll in Javascript?

In pygame, how do I blit an image when I collide with something and make it stay?

How do I make two unordered list fade in and fade out when my menu is clicked depending on which is showing?

How to make section fade on scroll?

How do I make a color fade in text?

How do i make my LinkedIn badge transition smoothly fade in and out?

How do I fade an image in swing?

How do I select three images at random and then fade them out with a new image?

CSS how to make an element fade in and then fade out?

How to make a 50% fade in and a 100% fade out?

How to make text fade out

Fade Out an Image when click on button, change image url and then fade in. How to do it?

How can I make an image bar to stay on top with the menu on mobile?

How to make image buttons stay in place when re sizing web browser