The setup is pretty basic. I have an event listener on the html element for mousemove. Using that event I can see how far you moved your mouse (event.movementX). I add that number to an existing counter. Sprinkle on some math (below) and you have the current frame. Easy peasy.
The sprite that I'm using has 4 rows and 12 columns. So I had to add in the math for wrapping around from position 0, 11 to 1, 0. That's why I use $sprite-height and $frame-height below.