Move a div automatically - add bg image

Move a div automatically - add bg image

by Chandana Thota

HTML

<!-- Move a div automatically - add bg image -->

<div id="box">
</div>

CSS

#box{
    position:absolute;
    width:400px;
    height:400px;
    background-color:red;
    left:100px;
    background:url('http://cdn2.scratch.mit.edu/get_image/gallery/248236_170x100.png?v=1378576109.73');
    background-repeat:no-repeat;
    
}

JavaScript

var pos = $('#box').position().left;
function loop() {
 //moving first div from left to right 
$('#box').css({left:0}); 
    $( "#box" ).animate({ "left": "+=500" }, 7000 , 'linear',
                        function() {loop();
        })
}
  loop();