JavaScript
Article

jQuery Create Smooth Moving Background

By Sam Deering

jQuery code snippet to help you create a smoother moving background animation. The move_background() function can be called once the DOM is fully loaded then the animation is set to process every 1 second.

$(document).ready(function(){
  setInterval ("move_background()", 100);
})

function move_background(){
  var backpos = $('body').css('background-position').replace(/px/gi,'').split(' ');
  var l_pos = String(backpos[0]-3)+'px 0px'
  $('body').css('background-position',l_pos)
}

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.