0

I am looking a help to move my container bg to move according to the 'scrollTop' for this, i wrote this function, but not work. any one help me. i decided to move my backgronud image with smooth way as well.

  $(window).scroll(function(){
var moveSize = $(window).scrollTop();
$('#container.takeover1').animate({ 
    backgroundPosition: "0px "+ parseInt(-moveSize)+'px',
    easing: 'swing'
    }, 3000 );

});

any one help me? thanks in advance.

3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
  • If you're just trying to keep the background static on the page when the window scrolls, why not just use `background-attachment: fixed` in your CSS? – Aleks G Jun 27 '11 at 09:22

2 Answers2

0
$('.bg').scroll(function(){
var x = $(this).scrollTop();
$(this).css('background-position','0% '+parseInt(-x/10)+'px');
});

FIDDLE DEMO

Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61
0

Try using negative vertical postiion eg

backgroundPosition: 0 -100px

James Westgate
  • 11,306
  • 8
  • 61
  • 68