jean rochefort
jean rochefort

Reputation: 1

Jquery Background position y +=1 issue

Every 80 ms, I want to add += 1 to div's background's Y position.
The issue is that it doesn't work. It only works if I add += 1 to x position.
How can I do this?

My code:

<script>
    $(function(){
        setInterval(oneSecondFunction, 80);
        });


    function oneSecondFunction() {
        $( '#grille1' ).css( 'background-position', '0 +=1' );

            }
</script>

Upvotes: 0

Views: 33

Answers (1)

Guffa
Guffa

Reputation: 700402

The background-position is a composite style consisting of the x and y position. You can't use relative values on composite styles, you have to set them separately:

$('#grille1').css('background-position-y', '+=1');

However, not all browsers support the separate styles for the background position, so for maximum compatibility you would need to keep track of the position so that you can create the composite value, or parse the composite value and do the relative calculation yourself.

Upvotes: 2

Related Questions