I did something similar on my site: http://bentruyman.com/ (clicking the little gear or pressing ` on your keyboard).
You can read the source for it here (sorry it's in CoffeeScript): https://github.com/bentruyman/bentruyman.com/blob/master/sou...
You can read the source for it here (sorry it's in CoffeeScript): https://github.com/bentruyman/bentruyman.com/blob/master/sou...