Trey Van Zandt
Trey Van Zandt

Reputation: 11

jQuery Scrolling image animation: Moving in the wrong direction

I'm fairly new to jQuery , and I'm trying to scroll and image downwards. The code I'm using is successfully scrolling the image, but sideways, and that's not what I need.

This is the code I'm using

$(function(){
    var y = 0;
    setInterval(function(){
        y -= 1;
        $('.scroller').css('background-position', y + 'px 0');
    }, 100);
})

If needed, I can provide the CSS and HTML, but those aren't the issue.

Upvotes: 1

Views: 62

Answers (1)

idmean
idmean

Reputation: 14875

Probably because you are changing the X axis... (Read more about background-position or Cartesian coordinate system)

Try this:

$('.scroller').css('background-position', '0 ' + y + 'px');

Upvotes: 1

Related Questions