I currently have three boxes that are functioning as expected. However, I am looking to automate this process to run every 30 seconds without requiring a 'click' event. You can refer to this fiddle http://jsfiddle.net/ykbgT/8493/. Any suggestions on how to achieve this?
The code snippet is provided below
<div id="box1" class="box">Div #1</div>
<div id="box2" class="box">Div #2</div>
<div id="box3" class="box">Div #3</div>
$('.box').click(function () {
$('.box').each(function () {
if ($(this).offset().left < 0) {
$(this).css("left", "150%");
} else if ($(this).offset().left > $('.box').width()) {
$(this).animate({
left: '50%',
}, 500);
} else {
$(this).animate({
left: '-150%',
}, 500);
}
});
});