Skip to content

Instantly share code, notes, and snippets.

@holocc
Created May 9, 2020 09:29
Show Gist options
  • Save holocc/3aa051625f2e3a7dae7d92db86aeedd2 to your computer and use it in GitHub Desktop.
Save holocc/3aa051625f2e3a7dae7d92db86aeedd2 to your computer and use it in GitHub Desktop.
点击穿透
<!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