Reputation: 1095
CSS
div {
width: 300px;
height: 500px;
background-image: url(http://i.imgur.com/6TbTDVs.jpg);
background-position: center top;
}
jQuery
$(window).scroll(function () {
var scrolledY = $(window).scrollTop();
var move = (scrolledY*0.2);
$('div').css('background-position','center -'+move*-1+'px');
});
http://jsfiddle.net/rgbjoy/8GkSg/
Upvotes: 1
Views: 126
Reputation: 149030
You're concatenating a -
in front of the number and multiply it by -1
, so it's trying to set the position to something like center --6px
, which is not valid.
Try this:
var move = scrolledY * -0.2;
$('div').css('background-position','center '+move+'px');
Upvotes: 1