Created
September 15, 2017 16:01
-
-
Save clohr/1d027dd80c49f1481e98d1283b113f18 to your computer and use it in GitHub Desktop.
Capture events on an iframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style> | |
* { | |
box-sizing: border-box; | |
} | |
body { | |
margin: 0; | |
padding: 0; | |
} | |
.container { | |
height: 300px; | |
overflow: hidden; | |
position: relative; | |
width: 100vw; | |
} | |
iframe { | |
width: 100%; | |
height: 100%; | |
} | |
.mask { | |
background: white; | |
opacity: 0.75; | |
cursor: pointer; | |
position: absolute; | |
bottom: 0; | |
left: 0; | |
right: 0; | |
top: 0; | |
height: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="mask"></div> | |
<iframe id="frame" width="100%" src="http://www.blackfynn.com"></iframe> | |
</div> | |
<script> | |
const mask = document.querySelector('.mask') | |
document.addEventListener('mouseover', evt => { | |
if (event.target.id !== 'frame') { | |
mask.style.display = 'block' | |
} | |
}) | |
mask.addEventListener('click', evt => { | |
mask.style.display = 'none' | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment