Thoughts are our internal ideas, opinions and creative musings.

Our Senses

spacer

Sep
6

Javascript Tool: Detect if a DOM element is truly visible

Jason Farrell on September 6th, 2012

Tweet

In Javascript, there’s no easy way to detect if a DOM element is truly visible. For example, if we have a typical slideshow, the images are usually off to the side and exist on the page. If you use jQuery’s (‘:visible’) method on an image out of bounds, it would return true, even though it isn’t visible to the user—it’s actually hidden outside of the bounds of an overflow:hidden container.

I created a tool that looks at an object and checks each of its parents to see if it’s still visible to the user.

It even works in Internet Explorer and doesn’t require jQuery.

I also only touched the surface on this—there are other instances where it will still return true, such as when an absolute or fixed element sits on top of what we’re detecting. I created a git repo for this if anyone wishes to expand on it: https://github.com/UseAllFive/ua5-js-utils

Usage:

Library:

spacer

Jason Farrell

Jason is a Co-Founder/Principle at Use All Five

Follow Jason Farrell on Twitter

This entry was posted by Jason Farrell on at and is filed under Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Sign in
spacer
  • Comment help
  • Get Livefyre
Post comment as
spacer spacer
Sort: Newest | Oldest

Blog Categories

  • Announcements
  • Design
  • Development
  • For Sale
  • Freebies
  • General
  • Press
  • Roundup
  • Social Media
  • Strategy
  • Support
  • Technology
  • Uncategorized

Blog Archives

  • September 2012
  • June 2012
  • May 2012
  • September 2011
  • June 2011
  • April 2011
  • February 2011
  • December 2010
  • April 2010
  • December 2009
  • November 2009
  • October 2009
  • August 2009
  • April 2009
  • February 2009
  • January 2009

Our Activity

UA5 on FB
Follow us on Twitter

Our Newsletter

Strategy Design Dev