I have the current function below, but feel like there is a much better way to write the same thing. I am looking for some insight on the most optimized way to write the same function below and why.
Note this is all inside of $(function(){});
m = function(){
$("#id").animate({marginRight : 0}, 'slow', function(){
$("#id").animate({marginRight : "15px"}, 'slow');
})
}
setInterval(m, 700)
It seems, based on what you are doing that you want to toggle an element’s motion over time. You can just set the original function
m()as a callback to be executed when the second, inner animation is done.