Last active
April 8, 2021 18:34
-
-
Save MichaelTr7/cb099ff26fdfceeca05ee5a926b560be to your computer and use it in GitHub Desktop.
A HTML/CSS/JavaScript Sliding Modal or Notifications.
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 lang="en" dir="ltr"> | |
<head> | |
<meta charset="utf-8"> | |
<title>CSS Modal</title> | |
<link rel="stylesheet" href="./Style.css"> | |
<script type="text/javascript" src="./Modal.js"></script> | |
</head> | |
<body> | |
<button id="Big_Button" type="button" name="button">Press<br>Button</button> | |
<div id="Modal">Modal</div> | |
</body> | |
</html> |
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
window.onload = function(){ | |
document.getElementById('Big_Button').addEventListener("click",Move_Modal); | |
} | |
function Move_Modal(){ | |
let Modal = document.getElementById('Modal'); | |
document.getElementById("Big_Button").classList.toggle("Light_Up"); | |
if(Modal.classList.contains('Slide_Down_Animation')){ | |
Modal.classList.remove('Slide_Down_Animation'); | |
void Modal.offsetWidth; | |
Modal.classList.add('Slide_Up_Animation'); | |
}else{ | |
Modal.classList.remove('Slide_Up_Animation'); | |
void Modal.offsetWidth; | |
Modal.classList.add('Slide_Down_Animation'); | |
} | |
} |
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
body{ | |
background-color: rgb(35,35,35); | |
} | |
:root{ | |
--Size: 6.5rem; | |
} | |
#Big_Button{ | |
position: absolute; | |
height: var(--Size); | |
width: var(--Size); | |
top: 5rem; | |
left: calc(25% - var(--Size)/2); | |
background-color: rgb(52,235,192); | |
border: none; | |
border-radius: 1rem; | |
font-family: Helvetica, Arial, sans-serif; | |
font-size: 1rem; | |
font-weight: bold; | |
color: rgba(0,0,0,0.5); | |
box-shadow: inset 1px 1px 2px 0px rgba(255,255,255,0.9); | |
transition: 0.2s; | |
} | |
#Big_Button:hover{ | |
transform: scale(1.05); | |
cursor: pointer; | |
} | |
#Big_Button.Light_Up{ | |
color: white; | |
} | |
#Modal{ | |
position: absolute; | |
--Height: 10rem; | |
--Width: 18rem; | |
top: calc(-1*var(--Height)); | |
left: calc((25% + var(--Size)/2 + 100%)/2 - var(--Width)/2); | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: var(--Height); | |
width: var(--Width); | |
background-color: gray; | |
border-radius: 1rem; | |
font-family: Helvetica, Arial, sans-serif; | |
font-size: 1rem; | |
font-weight: bold; | |
color: rgba(0,0,0,0.5); | |
box-shadow: inset 1px 1px 2px 0px rgba(255,255,255,0.35); | |
} | |
.Slide_Up_Animation{ | |
animation: Slide_Modal_Keyframes 0.3s ease forwards; | |
animation-direction: reverse; | |
} | |
.Slide_Down_Animation{ | |
animation: Slide_Modal_Keyframes 0.3s ease forwards; | |
animation-direction: normal; | |
} | |
@keyframes Slide_Modal_Keyframes { | |
0%{transform: translateY(0px); opacity: 0;} | |
50%{transform: translateY(15rem) scaleX(1.2); opacity: 0.7;} | |
100%{transform: translateY(13.5rem) scaleX(1); opacity: 1;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HTML/CSS/JavaScript Demo