Skip to content

Instantly share code, notes, and snippets.

@jhthorsen
Created April 7, 2013 13:41
Show Gist options
  • Save jhthorsen/5330541 to your computer and use it in GitHub Desktop.
Save jhthorsen/5330541 to your computer and use it in GitHub Desktop.
$.fn.passThrough = function() {
this.hover(
function() { $(this).fadeTo('fast', 0.2); },
function() { $(this).fadeTo('fast', 1.0); }
);
this.each(function() {
var self = this;
var last;
$(self).bind('click mousemove mouseout', function (e) {
var tmp = self.style.display || 'block';
var under;
e.preventDefault();
self.style.display = 'none';
under = document.elementFromPoint(e.clientX, e.clientY); // could also be pageX, pageY..?
self.style.display = tmp;
if(under) {
if(e.type == 'mousemove' && last != under) {
if(last) $(last).trigger('mouseout');
$(under).trigger('mouseover');
last = under;
console.log(last);
}
else {
$(under).trigger(e.type);
}
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment