Created
July 8, 2017 04:31
-
-
Save isaaguilar/672b7d841aff6ba9b42aa56debfa8585 to your computer and use it in GitHub Desktop.
Overlay on parent element css, js, html
This file contains hidden or 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
<html> | |
<head> | |
<style> | |
.overlay { | |
position: absolute; | |
top: 0; | |
left: 0px; | |
bottom: 0px; | |
right: 0px; | |
z-index: 2; | |
background-color: rgba(50, 50, 50, .5); | |
} | |
#parent { | |
position: relative; | |
display: block; | |
background: white; | |
height: 200px; | |
width: 200px; | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<div id="parent"> | |
<div id="overlay" /> | |
An overlay will be layed out over me when the button is pressed. | |
</div> | |
</div> | |
<div> | |
<button id="toggle">Set Overlay</button> | |
</div> | |
<script> | |
var overlay = $("#overlay") | |
var toggle = $("#toggle") | |
toggle.click(function() { | |
if (overlay.hasClass("overlay")) { | |
overlay.removeClass('overlay') | |
} else { | |
overlay.addClass('overlay') | |
} | |
}) | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment