Direction-aware hover with pure css

Developer
Size
3,596 Kb
Views
26,312

How do I make an direction-aware hover with pure css?

Just a little experiment to see if I could reproduce this hover effect with just css: http://tympanus.net/codrops/2012/04/09/direction-aware-hover-effect-with-css3-and-jquery/. What is a direction-aware hover with pure css? How do you make a direction-aware hover with pure css? This script and codes were developed by Zachary Olson on 10 November 2022, Thursday.

Direction-aware hover with pure css Previews

Direction-aware hover with pure css - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Direction-aware hover with pure css</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="hoverable"> <div class="hoverable-exit"></div> <div class="hoverable-exit"></div> <div class="hoverable-exit"></div> <div class="hoverable-exit"></div> <div class="hoverable-content-wrap"> <div class="hoverable-enter"></div> <div class="hoverable-enter"></div> <div class="hoverable-enter"></div> <div class="hoverable-enter"></div> <div class="hoverable-content"> Hovering Content. </div> </div>
</div>
<div class="hoverable"> <div class="hoverable-exit"></div> <div class="hoverable-exit"></div> <div class="hoverable-exit"></div> <div class="hoverable-exit"></div> <div class="hoverable-content-wrap"> <div class="hoverable-enter"></div> <div class="hoverable-enter"></div> <div class="hoverable-enter"></div> <div class="hoverable-enter"></div> <div class="hoverable-content"> Hovering Content. </div> </div>
</div>
<div class="hoverable"> <div class="hoverable-exit"></div> <div class="hoverable-exit"></div> <div class="hoverable-exit"></div> <div class="hoverable-exit"></div> <div class="hoverable-content-wrap"> <div class="hoverable-enter"></div> <div class="hoverable-enter"></div> <div class="hoverable-enter"></div> <div class="hoverable-enter"></div> <div class="hoverable-content"> Hovering Content. </div> </div>
</div>
</body>
</html>

Direction-aware hover with pure css - Script Codes CSS Codes

/* Logic */
.hoverable { position: relative; width: 200px; height: 200px;
}
.hoverable-content { opacity: 0; -webkit-animation-fill-mode: forwards; -webkit-animation-duration: 0.1s;
}
.hoverable:hover .hoverable-content { opacity: 1;
}
.hoverable-content-wrap, .hoverable-content, .hoverable-exit { position: absolute; width: 100%; height: 100%;
}
.hoverable-content-wrap { overflow: hidden;
}
/* Exit areas are full size and shifted to one side of square. */
.hoverable-exit { display: none; z-index: 2;
}
.hoverable:hover .hoverable-exit { display: block;
}
.hoverable-exit:nth-of-type(1), .hoverable-exit:nth-of-type(2) { width: 50px;
}
.hoverable-exit:nth-of-type(4), .hoverable-exit:nth-of-type(3) { height: 50px;
}
.hoverable-exit:nth-of-type(1) { left: 100%;
}
.hoverable-exit:nth-of-type(2) { right: 100%;
}
.hoverable-exit:nth-of-type(3) { bottom: 100%;
}
.hoverable-exit:nth-of-type(4) { top: 100%;
}
/* Enter areas are triangles inside box - actually built with rotated squares that are shifted halfway towards various sides */
.hoverable-enter { position: absolute; top: 0; left: 0; right: 0; bottom: 0; margin: auto; width: 141.42136px; height: 141.42136px; z-index: 1;
}
.hoverable-enter:nth-of-type(1) { -webkit-transform: translate(70%, 0%) rotate(45deg);
}
.hoverable-enter:nth-of-type(2) { -webkit-transform: translate(-70%, 0) rotate(45deg);
}
.hoverable-enter:nth-of-type(3) { -webkit-transform: translate(0, -70%) rotate(45deg);
}
.hoverable-enter:nth-of-type(4) { -webkit-transform: translate(0, 70%) rotate(45deg);
}
/* Enter area in use should cover whole area so other enter areas dont get triggered. */
.hoverable-enter:hover { display: block; -webkit-transform: none; z-index: 2; width: 100%; height: 100%;
}
.hoverable-enter:nth-of-type(1):hover ~ .hoverable-content { -webkit-animation-name: enter-left;
}
.hoverable:hover .hoverable-enter:nth-of-type(2):hover ~ .hoverable-content { -webkit-animation-name: enter-right;
}
.hoverable:hover .hoverable-enter:nth-of-type(3):hover ~ .hoverable-content { -webkit-animation-name: enter-bottom;
}
.hoverable:hover .hoverable-enter:nth-of-type(4):hover ~ .hoverable-content { -webkit-animation-name: enter-top;
}
.hoverable-exit:nth-of-type(1):hover ~ .hoverable-content-wrap .hoverable-content { -webkit-animation-name: exit-right;
}
.hoverable-exit:nth-of-type(2):hover ~ .hoverable-content-wrap .hoverable-content { -webkit-animation-name: exit-left;
}
.hoverable-exit:nth-of-type(3):hover ~ .hoverable-content-wrap .hoverable-content { -webkit-animation-name: exit-top;
}
.hoverable-exit:nth-of-type(4):hover ~ .hoverable-content-wrap .hoverable-content { -webkit-animation-name: exit-bottom;
}
/* Animations */
@-webkit-keyframes enter-top { from { bottom: -100%; } to { bottom: 0; }
}
@-webkit-keyframes enter-left { from { left: 100%; } to { left: 0; }
}
@-webkit-keyframes enter-bottom { from { bottom: 100%; } to { bottom: 0; }
}
@-webkit-keyframes enter-right { from { left: -100%; } to { left: 0; }
}
@-webkit-keyframes exit-top { from { top: 0; } to { top: -100%; }
}
@-webkit-keyframes exit-left { from { left: 0; } to { left: -100%; }
}
@-webkit-keyframes exit-bottom { from { top: 0; } to { top: 100%; }
}
@-webkit-keyframes exit-right { from { left: 0; } to { left: 100%; }
}
/* Styling */
body { width: 900px; margin: auto; background: #EDEBEE;
}
.hoverable { float: left; background: #CCC; margin: 50px 50px;
}
.hoverable-content { padding: 1em; box-sizing: border-box; background-color: #806973; color: #FFF; text-align: center; font-family: helvetica, sans-serif;
}
/*
.hoverable-exit { background: blue;
}*/
Direction-aware hover with pure css - Script Codes
Direction-aware hover with pure css - Script Codes
Home Page Home
Developer Zachary Olson
Username zacharyolson
Uploaded November 10, 2022
Rating 3
Size 3,596 Kb
Views 26,312
Do you need developer help for Direction-aware hover with pure css?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Zachary Olson (zacharyolson) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!