Pages

Jquery move background image horizontally on Scroll

How to Move the background image horizontal with the mouse as you scroll with Jquery and CSS which can also use as a horizontal parallax effect. This is done by adding a css class or an id and changing the background image with the JavaScript.

Jquery move background image horizontally on Scroll


The code

<script>
    $(window).scroll(function() {
        var x = $(this).scrollTop();
        $('.yourDivClass').css('background-position', parseInt(-x / 0.5) + 'px');
    });
</script>

No comments:

Post a Comment

Search This Blog