Created
September 22, 2013 21:30
-
-
Save DigiTec/6664011 to your computer and use it in GitHub Desktop.
In IE 11 every major browser now supports pointer-events, but until IE 11 gains wide adoption there will still be a large base of users who can't benefit from UI's which utilize this feature for "click through" UI's. In the meantime I figured I'd generate a list of click through mechanisms that vary based on properties used, nesting capabilities…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Utilize visibility. This will cause layout to be invalid and have to be recomputed once the element is made visible again. | |
function _clickThroughVisNested(evt) { | |
var localStyle = evt.target.style; | |
var oldVisibility = localStyle.display; | |
localStyle.visibility = "hidden"; | |
var target = document.elementFromPoint(evt.pageX, evt.pageY); | |
// Specific to my implementation. I want to only click through on certain types of elements. | |
if (target.classList.contains("achievement")) { | |
// Click is done here, before setting visibility back in order to support nesting scenarios. | |
target.click(); | |
} | |
localStyle.visibility = oldVisibility; | |
} | |
// Utilize display. This will cause layout to be invalid and have to be recomputed once the element is made visible again. | |
function _clickThroughDisplayNested(evt) { | |
var localStyle = evt.target.style; | |
var oldDisplay = localStyle.display; | |
localStyle.display = "none"; | |
var target = document.elementFromPoint(evt.pageX, evt.pageY); | |
// Specific to my implementation. I want to only click through on certain types of elements. | |
if (target.classList.contains("achievement")) { | |
// Click is done here, before setting display back in order to support nesting scenarios. | |
target.click(); | |
} | |
localStyle.display = oldDisplay; | |
} | |
// Utilize visibility. And reset visibility before calling "click". This doesn't support nesting, but prevents flashing | |
// if your overlay is not completely transparent. One example would be a gradient overlay that makes your elements appear | |
// to fade out at the edges of a container giving that carousel look. | |
function _clickThroughVis(evt) { | |
var localStyle = evt.target.style; | |
var oldVisibility = localStyle.display; | |
localStyle.visibility = "hidden"; | |
var target = document.elementFromPoint(evt.pageX, evt.pageY); | |
// Specific to my implementation. I want to only click through on certain types of elements. | |
if (!target.classList.contains("achievement")) { | |
target = null; | |
} | |
localStyle.visibility = oldVisibility; | |
// Click is done here, after setting visibility back in order to prevent flashing. | |
target.click(); | |
} | |
var _clickThrough = _clickThroughVis; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment