$.fn.passThrough = function (target) {
var $target = $(target);
return this.each(function() {
var style = this.style;
if ('pointerEvents' in style) {
style.pointerEvents = style.userSelect = style.touchCallout = 'none';
} else {
$(this).on('click tap mousedown mouseup mouseenter mouseleave', function (e) {
$target.each(function() {
var rect = this.getBoundingClientRect();
if (e.pageX > rect.left && e.pageX < rect.right &&
e.pageY > rect.top && e.pageY < rect.bottom)
$(this).trigger(e.type);
});
});
}
});
};
http://jsfiddle.net/yckart/BQw4U/
$('.overlay').passThrough('.box');
$('.box').click(function(){
$(this).toggleClass('active');
});
您的第二個鏈接(JavaScript解決方案)不再有效。它需要註冊帳戶。 錯誤:此垃圾箱是匿名創建的,其免費預覽時間已過期。 – Mai 2015-02-25 17:41:17
'ERR_CONNECTION_TIMED_OUT'這就是爲什麼你永遠不會把不屬於Stackoverflow的鏈接作爲答案。 *不錯的工作*從我這裏,你有一個downvote,因爲我現在看不到*真正的*答案。 – Fusseldieb 2017-10-25 16:10:28