I am trying to implement a loading animation on an input element. I want the animation to be triggered when the search button on the page has been clicked, and stop when the search has returned (in the callback).
As I'm using AngularJS, currently this is set up as an $http.get call and associated .success callback, so I already have the perfect places in which to add the triggering and the stopping.
Looking at my CodePen example you should be able to see what I am trying to do. The animation should run like this:
- first, the bar slides in from the left until it fully extends the width of the
input - then, it slides off in the same direction
- once it's fully disappeared, the animation restarts
In my example I have used :hover to trigger the animation, but eventually this should trigger from JavaScript.
How do I start and end the animation cycle in JavaScript, and how do I make it loop indefinitely until stopped?
[Credit]