html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!-- Created by Marco Cárdenas -->
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
</head>
<body>
<div id="out">
<div id="in">click "transparent"</div>
<div id="in2">click "opaque"</div>
</div>
<p id="offset">offset:0</p>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* Created by Marco Cárdenas */
#out {
background-color: blue;
width: 300px;
height:300px;
position: relative;
}
#in,#in2{
text-align:center;
color: white;
width: 100px;
height:150px;
left: 100px;
position:absolute;
}
#in {
background-color: red;
top: 0px;
pointer-events:none; /* <-- add this */
touch-action:none; /* <-- add this */
}
#in2{
background-color: green;
top: 150px;
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// unmodified code, just using css pointer-events:none; touch-action:none;
$(document).ready(
function() {
$('#out').on('click', function(e) {
$('#offset').text('offset: '+ e.offsetX);
})
}
);
// without pointer-events:none; touch-action:none; using e.stopPropagation() will make the children elements 'opaque' to the click event, disabling the click event when it is over the children elements.
// using e.stopPropagation()) on #in2
$(document).ready(
function() {
$('#out').on('click', function(e) {
$('#offset').text('offset: '+ e.offsetX);
}).children().on('click', function(e){
e.stopPropagation()
})
}
);
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run