This question is a continuation of How to click through objects
How do you click through an object, and make the object you're clicking through disappear(or alpha:0
)
This snippet has four small squares(all with different colors), and one black transparent one which covers all four.
So how can you make it so when you "point" at #box_a
, you're actually clicking through #box_e
. Well, you can use pointer-events: none
on #box_e
right? But wait a minute I also want #box_e
to disappear when my mouse is over #box_e
& to click through it!
By now it's probably evident that I cant use pointer-events: none
because then I couldn't read when my mice is over the object in question. How would I do this?
Here is my code(This is a minimalist example):
$(function() {
$("#box_a").click(function() {
alert("you clicked box_a")
});
$("#box_b").click(function() {
alert("you clicked box_b")
});
$("#box_c").click(function() {
alert("you clicked box_c")
});
$("#box_d").click(function() {
alert("you clicked box_d")
});
$("#box_e").click(function() {
alert("you clicked box_e(this shouldn't happen!)")
});
});
#box_a, #box_b, #box_c, #box_d {
height: 100px;
width: 100px;
position: relative;
}
#box_a {
top:0px;
left:0px;
background-color: red;
}
#box_b {
top:-100px;
left:100px;
background-color: blue;
}
#box_c {
top:-100px;
left:0px;
background-color: yellow;
}
#box_d {
top:-200px;
left:100px;
background-color: green;
}
#box_e {
width:200px;
height:200px;
top:-400px;
left:0px;
background-color: black;
opacity: .5;
position: relative;
pointer-events: none
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="box_a"></div>
<div id="box_b"></div>
<div id="box_c"></div>
<div id="box_d"></div>
<div id="box_e"></div>
</body>