JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://cdn.jsdelivr.net/velocity/1.2.2/velocity.min.js"></script>
<div id="topWaves" style="background: blue; height: 100px; width: 100px;"></div>

JavaScript

function Waves(selector){
  this.selector = selector;
  this.animateWaves = function(forward,backward,speed){
    var self = this;
    $(selector).velocity({translateX: forward},speed); 
      $(selector).velocity({translateX: backward}, speed, function () {self.animateWaves(forward,backward,speed);});
  };
};
var surfaceWaves = new Waves('#topWaves');
surfaceWaves.animateWaves('+=40','-=40','1000');