Javascript snippet for detecting whether user has viewed a dom element