The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Below is the html code for this video.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flip Opening Modal Button</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h4>Try clicking different sides of button.</h4>
<div class="container">
<div class="modal">
<p>Are you sure you want to do that ?</p>
<div class="btns">
<button class="yeah">Yeah</button>
<button class="nope">Nope</button>
</div>
</div>
<div class="mdl-btn">Launch Modal</div>
</div>
<script src="index.js"></script>
</body>
</html>
Below is the css code for this video.
style.css
* {
margin: 0;
padding: 0;
}
body {
display: flex;
height: 100vh;
width: 100%;
background-image: url(https://images.unsplash.com/photo-1622737133809-d95047b9e673?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1632&q=80);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 18px;
font-family: serif;
perspective: 1000px;
overflow: hidden;
}
h4 {
font-size: 4vw;
color: #dabfad;
letter-spacing: 2.8px;
margin-bottom: 2.8%;
}
.container.modal-visible~h4 {
display: none;
}
.container {
position: relative;
display: block;
height: 80px;
width: 200px;
transform-origin: 50% 50%;
transform-style: preserve-3d;
text-align: center;
transition: width 0.75s cubic-bezier(0.25, 1, 0.33, 1), height 0.75s cubic-bezier(0.25, 1, 0.33, 1), transform 0.75s cubic-bezier(0.25, 1, 0.33, 1);
}
.mdl-btn {
position: absolute;
display: block;
height: 100%;
width: 100%;
background-color: #fcfc73;
color: #fea81f;
line-height: 80px;
border-radius: 4px;
letter-spacing: 5.5px;
backface-visibility: hidden;
cursor: pointer;
transition: background-color 0.25s ease, color 0.25s ease;
}
.mdl-btn:hover {
background-color: #fea81f;
color: #fcfc73;
}
.container.modal-visible .mdl-btn {
line-height: 160px;
pointer-events: none;
}
.modal {
position: absolute;
display: flex;
height: 100%;
width: 100%;
background-color: #000000;
background-image: linear-gradient(-55deg, #ff000040, #00ff0040);
color: #ffffff;
border-radius: 8px;
transform: translateZ(-4px) rotateX(180deg);
flex-direction: column;
align-items: center;
justify-content: center;
box-shadow: none;
overflow: hidden;
transition: box-shadow 0.75s ease;
}
.modal p {
font-size: calc(1vw + 5.5px);
font-family: monospace;
letter-spacing: 1px;
margin-bottom: 5%;
}
.btns {
display: flex;
width: 100%;
align-items: center;
justify-content: space-around;
}
.btns button {
width: 33%;
background-color: transparent;
font-size: 20px;
font-family: monospace;
border: none;
border-radius: 4px;
letter-spacing: 1.9px;
padding: 15px 30px;
cursor: pointer;
transition: background-color 0.25s ease, color 0.25s ease, transform 0.25s ease, border 0.25s ease;
}
.btns button:focus, .btns button:hover {
outline: none;
transform: scale(1.125);
animation: buttonAnim 1.45s infinite;
}
@keyframes buttonAnim {
0%, 40%, 80%, 100% {
font-size: 16px;
letter-spacing: 1px;
}
20%, 60% {
font-size: 20px;
letter-spacing: 2.8px;
}
}
.btns button.yeah {
background-color: #49e82b;
color: #ffffff;
border: none;
}
.btns button.yeah:hover {
background-color: transparent;
color: #73ff59;
border: 1px solid #73ff59;
}
.btns button.nope {
background-color: #fd1c03;
color: #ffffff;
border: none;
}
.btns button.nope:hover {
background-color: transparent;
color: #fd5b63;
border: 1px solid #fd5b63;
}
.container.modal-visible .modal {
box-shadow: 0 0 28px #ffffffbf;
}
.container[data-direction=left] .modal, .container[data-direction=right] .modal {
transform: translateZ(-4px) rotateY(180deg);
}
.container.modal-visible {
height: 25%;
width: 50%;
}
.container.modal-visible::before {
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 100vh;
width: 100vw;
backdrop-filter: blur(5.5px);
}
.container[data-direction=top].modal-visible {
transform: rotateX(180deg);
}
.container[data-direction=left].modal-visible {
transform: rotateY(-180deg);
}
.container[data-direction=bottom].modal-visible {
transform: rotateX(-180deg);
}
.container[data-direction=right].modal-visible {
transform: rotateY(180deg);
}
Below is the javascript code for this video.
index.js
const container = document.querySelector(".container");
const modalButton = container.querySelector(".mdl-btn");
const buttonYeah = container.querySelector(".modal .yeah");
const buttonNope = container.querySelector(".modal .nope");
modalButton.addEventListener("click", function (e) {
var mx = e.clientX - container.offsetLeft;
var my = e.clientY - container.offsetTop;
var h = container.offsetHeight;
var w = container.offsetWidth;
var directions = [{ id: "top", x: w / 2, y: 0 }, { id: "left", x: 0, y: h / 2 }, { id: "bottom", x: w / 2, y: h }, { id: "right", x: w, y: h / 2 }];
directions.sort((a, b) => distance(mx, my, a.x, a.y) - distance(mx, my, b.x, b.y));
container.setAttribute("data-direction", directions.shift().id);
container.classList.add("modal-visible");
});
buttonYeah.addEventListener("click", () => container.classList.remove("modal-visible"));
buttonNope.addEventListener("click", () => container.classList.remove("modal-visible"));
function distance(x1, y1, x2, y2) {
var dx = x1 - x2;
var dy = y1 - y2;
return Math.sqrt(dx * dx + dy * dy);
}
Thanks for visiting