Creating a custom directive animated with JavaScript