I would have to think about the element a bit, but off the top of my head I would try something like this.
In your css:
Then for the actual element, something like this:
Then I'd place the script tag at the foot of your document:
Some things might need to be tweaked a bit in the css, and in trying to have everything loads before the code runs, but hopefully this will give you somewhere to start.