Trang chá»§
Button Hover Effects
Save
Settings
Sign Up
Log In
Save
Settings
HTML
Copy
<div class="centerer"> <div class="wrap"> <a class="btn-0" href="#">Swipe</a> <a class="btn-1" href="#">Diagonal Swipe</a> <a class="btn-1-2" href="#">Double Swipe</a> <a class="btn-2" href="#">Diagonal Close</a> <a class="btn-3" href="#"><span>Zoning In</span></a> <a class="btn-4" href="#"><span>4 Corners</span></a> <a class="btn-5" href="#">Slice</a> </div> <div class="wrap"> <a class="btn-6" href="#">Position Aware<span></span></a> <a class="btn-7" href="#"><span>Alternate</span></a> <a class="btn-8" href="#">Smoosh</a> <a class="btn-9" href="#"><span>Vertical Overlap</span></a> <a class="btn-10" href="#"><span>Horizontal Overlap</span></a> <a class="btn-11" href="#">Collision</a> </div> </div>
CSS
Copy
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400|Raleway:300); html { padding-top: 50px; font-family: "Open Sans", Helvetica, arial, sans-serif; text-align: center; background-color: #eeeeee; } html *, html *:before, html *:after { box-sizing: border-box; transition: 0.5s ease-in-out; } html i, html em, html b, html strong, html span { transition: none; } *:before, *:after { z-index: -1; } h1, h4 { font-family: "Raleway", "Open Sans", sans-serif; margin: 0; line-height: 1; } a { text-decoration: none; line-height: 80px; color: black; } .centerer { width: 100%; max-width: 600px; margin: 0 auto; padding: 0 1rem; } @media (min-width: 600px) { .wrap { width: 50%; float: left; } } [class^=btn-] { position: relative; display: block; overflow: hidden; width: 100%; height: 80px; max-width: 250px; margin: 1rem auto; text-transform: uppercase; border: 1px solid currentColor; } .btn-0 { color: #cd5f95; } .btn-0:before { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background-color: #76284e; transform: translateX(-100%); } .btn-0:hover { color: #f0d0e0; } .btn-0:hover:before { transform: translateX(0); } .btn-1 { color: #3e4d4e; } .btn-1:before { content: ""; position: absolute; top: 0; right: -50px; bottom: 0; left: 0; border-right: 50px solid transparent; border-bottom: 80px solid #111b1c; transform: translateX(-100%); } .btn-1:hover { color: #c6cbcb; } .btn-1:hover:before { transform: translateX(0); } .btn-1-2 { color: #83999d; } .btn-1-2:before, .btn-1-2:after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border-bottom: 80px solid #415154; } .btn-1-2:before { right: -50px; border-right: 50px solid transparent; transform: translateX(-100%); } .btn-1-2:after { left: -50px; border-left: 50px solid transparent; transform: translateX(100%); } .btn-1-2:hover { color: #dbe1e2; } .btn-1-2:hover:before { transform: translateX(-40%); } .btn-1-2:hover:after { transform: translateX(40%); } .btn-2 { color: #9d4b4d; } .btn-2:before, .btn-2:after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; } .btn-2:before { right: -50px; border-right: 50px solid transparent; border-bottom: 80px solid #541a1c; transform: translateX(-100%); } .btn-2:after { left: -50px; border-left: 50px solid transparent; border-top: 80px solid #541a1c; transform: translateX(100%); } .btn-2:hover { color: #e2cacb; } .btn-2:hover:before { transform: translateX(-49%); } .btn-2:hover:after { transform: translateX(49%); } .btn-3:before, .btn-3:after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border-top: 40px solid #676c4d; border-bottom: 40px solid #676c4d; } .btn-3:before { border-right: 40px solid transparent; transform: translateX(-100%); } .btn-3:after { border-left: 40px solid transparent; transform: translateX(100%); } .btn-3:hover { color: #eaecdf; } .btn-3:hover:before { transform: translateX(-30%); } .btn-3:hover:after { transform: translateX(30%); } .btn-4 { color: #7164cf; } .btn-4:before, .btn-4:after, .btn-4 span:before, .btn-4 span:after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background-color: #352c77; } .btn-4:before { transform: translate(-100%, -100%); } .btn-4:after { transform: translate(-100%, 100%); } .btn-4 span:before { transform: translate(100%, -100%); } .btn-4 span:after { transform: translate(100%, 100%); } .btn-4:hover { color: #d5d2f1; } .btn-4:hover:before { transform: translate(-50%, -50%); } .btn-4:hover:after { transform: translate(-50%, 50%); } .btn-4:hover span:before { transform: translate(50%, -50%); } .btn-4:hover span:after { transform: translate(50%, 50%); } .btn-5 { color: #acd074; } .btn-5:after { content: ""; width: 0; height: 0; -webkit-transform: rotate(360deg); border-style: solid; border-width: 0 0 0 0; border-color: transparent #5e7837 transparent transparent; position: absolute; top: 0; right: 0; } .btn-5:before { content: ""; width: 0; height: 0; -webkit-transform: rotate(360deg); border-style: solid; border-width: 0 0 0 0; border-color: transparent transparent transparent #5e7837; position: absolute; bottom: 0; left: 0; } .btn-5:before, .btn-5:after { content: ""; position: absolute; width: 0; height: 0; border: 0 solid; transform: rotate(360deg); } .btn-5:before { bottom: 0; left: 0; border-color: transparent transparent transparent #5e7837; } .btn-5:after { top: 0; right: 0; border-color: transparent #5e7837 transparent transparent; } .btn-5:hover { color: #e7f1d6; } .btn-5:hover:before, .btn-5:hover:after { border-width: 80px 262.5px; } .btn-6 { color: #a7b7a2; } .btn-6 span { position: absolute; display: block; width: 0; height: 0; border-radius: 50%; background-color: #5b6658; transition: width 0.4s ease-in-out, height 0.4s ease-in-out; transform: translate(-50%, -50%); z-index: -1; } .btn-6:hover { color: #e5eae4; } .btn-6:hover span { width: 225%; height: 562.5px; } .btn-6:active { background-color: #98aa92; } .btn-7 { color: #8a37c1; } .btn-7:before, .btn-7:after, .btn-7 span:before, .btn-7 span:after { content: ""; position: absolute; top: 0; width: 25.25%; height: 0; background-color: #460c6d; } .btn-7:before { left: 0; } .btn-7:after { left: 50%; } .btn-7 span:before, .btn-7 span:after { top: auto; bottom: 0; } .btn-7 span:before { left: 25%; } .btn-7 span:after { left: 75%; } .btn-7:hover { color: #ddc4ed; } .btn-7:hover:before, .btn-7:hover:after, .btn-7:hover span:before, .btn-7:hover span:after { height: 80px; } .btn-8 { color: #ab77a5; } .btn-8:before, .btn-8:after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background-color: #5e3959; } .btn-8:before { transform: translateY(-100%); } .btn-8:after { transform: translateY(100%); } .btn-8:hover { color: #e6d7e5; } .btn-8:hover:before { transform: translateY(-50%); } .btn-8:hover:after { transform: translateY(50%); } .btn-9 { color: #b66aa8; } .btn-9:before, .btn-9:after, .btn-9 span:before, .btn-9 span:after { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 0; background-color: rgba(101, 48, 92, 0.25); transition: 0.4s ease-in-out; } .btn-9:after, .btn-9 span:before { top: auto; bottom: 0; } .btn-9 span:before, .btn-9 span:after { transition-delay: 0.4s; } .btn-9:hover { color: #ead3e6; } .btn-9:hover:before, .btn-9:hover:after, .btn-9:hover span:before, .btn-9:hover span:after { height: 80px; } .btn-9:active { background-color: #a95099; } .btn-10 { color: #63a8a7; } .btn-10:before, .btn-10:after, .btn-10 span:before, .btn-10 span:after { content: ""; position: absolute; top: 0; left: 0; width: 0; height: 80px; background-color: rgba(43, 92, 91, 0.25); transition: 0.4s; } .btn-10:after, .btn-10 span:before { left: auto; right: 0; } .btn-10 span:before, .btn-10 span:after { transition-delay: 0.4s; } .btn-10:hover { color: #d1e6e5; } .btn-10:hover:before, .btn-10:hover:after, .btn-10:hover span:before, .btn-10:hover span:after { width: 250px; } .btn-10:active { background-color: #489997; } @-webkit-keyframes criss-cross-left { 0% { left: -20px; } 50% { left: 50%; width: 20px; height: 20px; } 100% { left: 50%; width: 375px; height: 375px; } } @keyframes criss-cross-left { 0% { left: -20px; } 50% { left: 50%; width: 20px; height: 20px; } 100% { left: 50%; width: 375px; height: 375px; } } @-webkit-keyframes criss-cross-right { 0% { right: -20px; } 50% { right: 50%; width: 20px; height: 20px; } 100% { right: 50%; width: 375px; height: 375px; } } @keyframes criss-cross-right { 0% { right: -20px; } 50% { right: 50%; width: 20px; height: 20px; } 100% { right: 50%; width: 375px; height: 375px; } } .btn-11 { position: relative; color: #486f6c; } .btn-11:before, .btn-11:after { position: absolute; top: 50%; content: ""; width: 20px; height: 20px; background-color: #285552; border-radius: 50%; } .btn-11:before { left: -20px; transform: translate(-50%, -50%); } .btn-11:after { right: -20px; transform: translate(50%, -50%); } .btn-11:hover { color: #c9d5d4; } .btn-11:hover:before { -webkit-animation: criss-cross-left 0.8s both; animation: criss-cross-left 0.8s both; -webkit-animation-direction: alternate; animation-direction: alternate; } .btn-11:hover:after { -webkit-animation: criss-cross-right 0.8s both; animation: criss-cross-right 0.8s both; -webkit-animation-direction: alternate; animation-direction: alternate; }
JS
Copy
$(function() { $('.btn-6') .on('mouseenter', function(e) { var parentOffset = $(this).offset(), relX = e.pageX - parentOffset.left, relY = e.pageY - parentOffset.top; $(this).find('span').css({top:relY, left:relX}) }) .on('mouseout', function(e) { var parentOffset = $(this).offset(), relX = e.pageX - parentOffset.left, relY = e.pageY - parentOffset.top; $(this).find('span').css({top:relY, left:relX}) }); });