VictorHub,
var animated_element = document.getElementById('bg');
var frame_width = animated_element.offsetWidth;
var total_frames = 4;
var frame_count = 0;
var timer = setInterval(function(){
var new_x = (frame_count * frame_width) * -1;
animated_element.style.backgroundPosition = new_x+'px 0px';
if (frame_count < total_frames){
frame_count += 1;
}else{
window.clearTimeout(timer)
}
},400);