1

I found an easy code to create a parallax effect with jquery:

function parallax(intensity, element) {
    $(window).scroll(function() {
        var scrollTop = $(window).scrollTop();
        var objPos = scrollTop / intensity + 'px';
        element.css('transform', 'translateY(' + objPos + ')');
    });
}

I completly understand how this code works, but how do I apply this on different elements?

So for example #div1 with intensity 3, #div2 with intensity 5.

Thank you for you help in advance! :)

Adriano
  • 3,788
  • 5
  • 32
  • 53
Philipp
  • 198
  • 1
  • 16
  • Possible duplicate of [How to create parallax effect like this?](https://stackoverflow.com/questions/23178762/how-to-create-parallax-effect-like-this) – Parijat Purohit Oct 30 '17 at 08:30

1 Answers1

1

You created the function, now you just need to call it:

parallax(3, $('#div1'));
parallax(5, $('#div2'));

Try this and let me know how it goes.

Adriano
  • 3,788
  • 5
  • 32
  • 53