How does this work? See notes in the JavaScript at the bottom of this HTML file (view source).
Like this? Thank @macloo
View on GitHub.