I have a div that auto-scrolls from the left to right. I use jQuery to achieve that. In the jQuery callback function, I called the function that makes it auto-scrolls from the left to right. However, the callback function fails and it doesn't scroll from the left to right again. What am I doing wrong?
function scroll() {
var element = document.getElementById("scroll");
var width = element.scrollWidth;
$(document).ready(function(){
$("#scroll").animate({scrollLeft: width}, 5000, function(){
scroll();
});
});
} //end of scroll()
scroll();
#scroll {
display: inline-block;
padding: .5%;
border: 1px solid black;
white-space: nowrap;
width: 10%;
overflow-x: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id = "scroll">one two three four five six seven eight nine ten</div>