I am going to take a guess at your code and say that the issue lies in the line where you update the 'location1.x' value using the 'Math.sin' function returning -1 or 1, in your case 1. Currently, you are using 'Math.abs' on the returned value of 'Math.sin', which always give you a positive value.
Math.sin()[
^] and
Math.abs()[
^]
The following line should solve the issue -
Replace this line
location1.x += Math.abs( Math.sin(speedModifier*(timer/6000))) ;
with -
location1.x = (ctx.canvas.width - 2 * radius) / 2 + (ctx.canvas.width - 2 * radius) / 2 * Math.sin(speedModifier * (timer / 6000));
I created a jsfiddle which works fine at
To and Fro Ball Animation[
^]