Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
点击穿透
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css">
.button {
background: red;
height: 300px;
}
.wrapper {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: blue;
opacity: .5;
}
</style>
</head>
<body>
<div class="wrapper">
</div>
<div class="button">click me</div>
</body>
<script>
function addEvent (name, target) {
target = target || document.body
target.addEventListener(name, function () {
console.log(target, name)
})
}
const wrapper = document.querySelector('.wrapper')
const button = document.querySelector('.button')
wrapper.addEventListener('touchstart', function () {
document.body.removeChild(wrapper)
})
button.addEventListener('click', function () {
console.log('button click')
})
// addEvent('touchstart')
// addEvent('click')
// addEvent('touchend')
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.