JSFiddle - React, Tailwind, and code Playground

by Amit Vishwakarma

HTML

<div class="one"></div>
<div class="two"></div>
<div class="three"></div>

CSS

.one, .two, .three {
    width: 450px;
    height: 250px;
}

.one {
    background: url('http://lorempixel.com/output/cats-h-c-450-500-6.jpg') no-repeat;
}

.two {
    background: url('http://lorempixel.com/output/cats-h-c-450-500-7.jpg') no-repeat;
}

.three {
    background: url('http://lorempixel.com/output/cats-h-c-450-500-1.jpg') no-repeat;
}

JavaScript

$.fn.parallax = function(strength) {
    var scroll_top = $(window).scrollTop();
    var move_value = Math.round(scroll_top * strength);
    this.css('background-position-y', '-'+ move_value +'px');
};

$(window).on('scroll', function() {
    $('.one').parallax(0.5);
    $('.two').parallax(0.6);
    $('.three').parallax(0.2);
});