Interval based version

I have modified the code to trigger events at a regular interval, rather than on every scroll event. Improves performance (especially when used on many elements).