I have been dedicating my day to mastering the art of website development. However, I am facing a challenge that is proving to be quite difficult. I am looking to create a smooth transition effect where an image gradually blurs while scrolling down, and returns to its original state when scrolling back up.
Below is a snippet from my HTML and CSS related to the section I am working on:
.home-header {
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(write.jpg);
background-size: cover;
margin: auto;
}
.blur {
opacity: 0;
-webkit-filter: blur(10px);
-moz-filter: blur(10px);
-o-filter: blur(10px);
-ms-filter: blur(10px);
filter: blur(10px);
}
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<div class="home-header blur">
<div class="banner-text">
<p>Banner text</p>
<a href="#" class="btn btn-primary">Button</a>
</div>
</div>
<script>
$(document).ready(function() {
$(window).scroll(function(e) {
var s = $(window).scrollTop(),
opacityVal = (s / 200);
$('.blur').css('opacity', opacityVal);
});
});
</script>
Any help would be greatly appreciated!