JavaScript
Article
By Sam Deering

jQuery Create Smooth Moving Background

By Sam Deering
Help us help you! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min

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.

--ADVERTISEMENT--

$(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)
}
Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the most important and interesting stories in tech. Straight to your inbox, daily.Is it good?