多种按钮悬浮点击动画特效
代码语言:html
所属分类:悬停
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css'> <style> @import url("https://fonts.googleapis.com/css?family=Montserrat&display=swap"); html, body { margin: 0px; background: #000; } .cbtn-wrap { overflow: hidden; text-align: center; margin-top: 50px; } #cbtn-title { position: relative; font-family: Montserrat; color: #fff; font-size: 24px; text-transform: uppercase; font-weight: 600; text-decoration: underline; } .cbtn-o { display: inline-block; position: relative; } .cbtn-o > .cbtn-i { position: relative; z-index: 3; cursor: pointer; margin: 40px 20px; padding: 10px 25px; border-radius: 100px; font-family: Montserrat; font-weight: 600; color: #fff; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); transition: 250ms cubic-bezier(0, 0.5, 0.5, 1); -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .cbtn-o > .cbtn-i[data-mode="0"] { background: #e96651; box-shadow: 0px 0px 0px #e96651; } .cbtn-o > .cbtn-i[data-mode="0"]:hover { transform: scale(0.9); background: #efaf60; box-shadow: 0px 0px 30px #efaf60; } .cbtn-o > .cbtn-i[data-mode="0"]:active { transform: scale(1); } .cbtn-o > .cbtn-i[data-mode="1"] { background: #3770a0; box-shadow: 0px 0px 0px #3770a0; } .cbtn-o > .cbtn-i[data-mode="1"]:hover { transform: scale(0.9); background: #77b6ea; box-shadow: 0px 0px 20px #77b6ea; } .cbtn-o > .cbtn-i[data-mode="1"]:active { transform: scale(0.6); } .cbtn-o > .cbtn-i[data-mode="2"] { background: #30a254; box-shadow: 0px 0px 0px #30a254; transition: 350ms cubic-bezier(0, 0.5, 0.5, 1); } .cbtn-o > .cbtn-i[data-mode="2"]:hover { transform: scale(0.9); background: #51e980; box-shadow: 0px 0px 30px #51e980; } .cbtn-o > .cbtn-i[data-mode="2"]:active { transform: scale(0.9) rotateX(-360deg); } .cbtn-o > .cbtn-i[data-mode="3"] { background: #8e54ff; box-shadow: 0px 0px 0px #8e54ff; } .cbtn-o > .cbtn-i[data-mode="3"]:hover { transform: scale(0.9); background: #a93ee0; box-shadow: 0px 0px 30px #a93ee0; } .cbtn-o > .cbtn-i[data-mode="3"]:active { transform: scale(0.9) rotate(-360deg); } .cbtn-o > .cbtn-i[data-mode="4"] { background: #ff0000; box-shadow: 0px 0px 0px #ff0000; } .cbtn-o > .cbtn-i[data-mode="4"]:hover { transform: scale(0.9); background: #ff0000; box-shadow: 0px 0px 30px #ff0000; } .cbtn-o > .cbtn-i[data-mode="4"]:active { transition: none; filter: blur(7px); color: transparent; } .cbtn-o > canvas { position: absolute; z-index: 2; top: 0px; left: 0px; } .cbtn-nav { color: #fff; display: inline-block; position: relative; z-index: 1; font-size: 18px; padding: 10px; cursor: pointer; text-shadow: 2px 2px 4px #111; } .cbtn-nav#nav-next { margin-left: 20px; } .cbtn-nav#nav-next::before { left: 15px; } .cbtn-nav#nav-prev { margin-right: 20px; } .cbtn-nav#nav-prev::before { left: 17px; } .cbtn-nav:hover::before { width: 40px; height: 40px; } .cbtn-nav::before { content: ""; position: absolute; border-radius: 100px; top: 20px; transform: translate(-50%, -50%); height: 0px; width: 0px; background: #333333; z-index: -1; transition: 150ms ease-in-out; } .next_anim { animation: next 600ms ease; pointer-events: none; } .prev_anim { animation: prev 600ms ease; pointer-events: none; } .info-wrap { font-family: Montserrat; } .info-wrap > .info-text { display: inline-block; color: #333333; width: 30%; max-width: 300px; padding: 15px; background: #ccc; border-radius: 100px; font-size: 14px; font-weight: 600; } @keyframes next { 0% { left: 0px; opacity: 1; } 50% { left: 300px; opacity: 0; } 50.1% { left: -300px; opacity: 0; } 100% { left: 0px; opacity: 1; } } @keyframes prev { 0% { left: 0px; opacity: 1; } 50% { left: -300px; opacity: 0; } 50.1% { left: 300px; opacity: 0; } 100% { left: 0px; opacity: 1; } } </style> </head> <body translate="no"> <div class="cbtn-wrap"> <div id="cbtn-title"></div> <div class="cbtn-nav" id="nav-prev"> <i class="fas fa-chevron-left"></i> </div> <div class="cbtn-o" id="cbtn1"> <div class="cbtn-i" data-mode="0">Hover / Click / Hold</div> </div> <div class="cbtn-nav" id="nav-next"> <i class="fas fa-chevron-right"></i> </div> <div class="info-wrap"> <div class="info-text"></div> </div> </div> <script> window.onload = function () { var canvas = document.createElement("canvas"); var innerBtn = document.querySelector("#cbtn1 .cbtn-i"); var outerBtn = document.getElementById("cbtn1"); var nextBtn = document.getElementById("nav-next"); var prevBtn = document.getElementById("nav-prev"); var btnTitle = document.getElementById("cbtn-title"); var tipText = document.querySelector(".info-wrap .info-text"); outerBtn.appendChild(canvas); var ctx = canvas.getContext("2d"); w = ctx.canvas.width = outerBtn.offsetWidth; h = ctx.canvas.height = outerBtn.offsetHeight; dots = []; hoverFlag = false; clickFlag = false; mode = 0; nt = 0; tip = 0; tips = [ "鼠标放上去试试", "The spacing/canvas area around the button can be easily adjusted via CSS margin.", "Tested in IE and on various mobile devices.", "无需其他库", "Imagine the endless possibilities :)", "In this case there is only one Button which is being controlled via JS.", "Using a black background for the best contrast.", "More effects coming soon..."]; modeSets = [ { name: "Fireflies", maxDots: 75, maxSpeed: 3, minSpeed: 1, emitRate: 10, emitNum: 2, radius: 2, trail: 0.2, maxTime: 1500, minTime: 750, glow: 10, hueMin: 15, hueMax: 55 }, { name: "Hyper Jump", maxDots: 100, maxSpeed: 3, minSpeed: 1, emitRate: 10, emitNum: 3, radius: 1.75, trail: 0.06, maxTime: 700, minTime: 300, glow: 7, hueMin: 170, hueMax: 230 }, { name: "Focus", maxDots: 75, maxSpeed: 2, minSpeed: 0.5, emitRate: 10, emitNum: 2, radius: 7, trail: 1, maxTime: 1000, minTime: 500, .........完整代码请登录后点击上方下载按钮下载查看
网友评论0