I'm experimenting with creating unique parallax effects and I'm wondering if it's possible to make a div with a background image set to background-attachment: fixed
scroll at a slower rate than the normal scroll speed, rather than staying completely still?
This is the CSS code I currently have:
.parallax{
height: 400px !important;
width: 100%;
background-size: cover;
background-attachment: fixed;
}
Here is my div element:
<div class="parallax" style="background-image: url('img/image.jpg'); ">
</div>
I've attempted this JavaScript code:
$('div.parallax').each(function(){
$scroll_speed = 10;
$this = $(this);
$(window).scroll(function() {
$bgScroll = -(($win.scrollTop() - $this.offset().top)/ $scroll_speed);
$bgPosition = 'center '+ $bgScroll + 'px';
$this.css({ backgroundPosition: $bgPosition });
});
});
It appears to be functioning correctly, but I'm having trouble adjusting the scroll_speed variable. Can anyone provide assistance on how to modify this value successfully?