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! :)

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, it worked! :) I just forgot the syntax to do this...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.