3d粒子按钮特效
代码语言:html
所属分类:粒子
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Emoji Particle Physics with JavaScript | @keyframers 2.21.0</title> <style> @import url("https://fonts.googleapis.com/css?family=Fascinate+Inline&display=swap"); html, body { height: 100%; width: 100%; padding: 0; margin: 0; overflow: hidden; } * { box-sizing: border-box; position: relative; } body { display: flex; justify-content: center; align-items: center; background: #14192C; } .treat-button { font-family: 'Fascinate Inline', cursive; font-size: 4vmin; -webkit-appearance: none; -moz-appearance: none; appearance: none; background: linear-gradient(tobottom, #F46001, #E14802); border: none; color: #FFF; border-radius: 2em; padding: .6em 1.5em; overflow: hidden; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; cursor: pointer; z-index: 1; box-shadow: 0 0 1em rgba(255, 255, 255, 0.2); transition: box-shadow 0.2s, -webkit-transform 0.1s cubic-bezier(0.5, 0, 0.5, 1); transition: transform 0.1s cubic-bezier(0.5, 0, 0.5, 1), box-shadow 0.2s; transition: transform 0.1s cubic-bezier(0.5, 0, 0.5, 1), box-shadow 0.2s, -webkit-transform 0.1s cubic-bezier(0.5, 0, 0.5, 1); outline: none; } .treat-button:hover { box-shadow: 0 0 2em rgba(255, 255, 255, 0.3); } .treat-button:active { -webkit-transform: scale(0.8) translateY(10%); transform: scale(0.8) translateY(10%); transition-timing-function: cubic-bezier(0.5, 0, 0.5, 1); } .treat { --scale-x: 0; --scale-y: 0; pointer-events: none; display: block; position: absolute; top: 0; left: calc(50% - .5rem); border-radius: 50%; width: 1em; height: 1em; display: flex; justify-content: center; align-items: center; font-size: 5vmin; -webkit-transform: translate(calc( var(--x) *1px ), calc( var(--y) * 1px )) translate(-50%, -50%); transform: translate(calc( var(--x) *1px ), calc( var(--y) * 1px )) translate(-50%, -50%); pointer-events: none; -webkit-animation: treat-enter 0.1s ease-in backwards, treat-exit 300ms linear calc( (var(--lifetime, 3000) * 1ms) - 300ms) forwards; animation: treat-enter 0.1s ease-in backwards, treat-exit 300ms linear calc( (var(--lifetime, 3000) * 1ms) - 300ms) forwards; } @-webkit-keyframes treat-enter { from { opacity: 0; } } @keyframes treat-enter { from { opacity: 0; } } @-webkit-keyframes treat-exit { to { opacity: 0; } } @keyframes treat-exit { to { opacity: 0; } } .treat .inner { -webkit-animation: inner-rotate .6s linear infinite; animation: inner-rotate .6s linear infinite; -webkit-transform: rotate(calc(-1turn * var(--direction) )); transform: rotate(calc(-1turn * var(--direction) )); } @-webkit-keyframes inner-rotate { to { -webkit-transform: none; transform: none; } } @keyframes inner-rotate { to { -webkit-transform: none; transform: none; } } </style> </head> <body translate="no"> <div class="treat-wrapper"> <button class="treat-button">Treats!</button> </div> <script> let width = window.innerWidth; let height = window.innerHeight; const body = document.body; const elButton = document.querySelector(".treat-button"); const elWrapper = document.querySelector(".treat-wrapper"); function getRandomArbitrary(min, max) { return Math.random() * (max - min) + min; } function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } const treatmojis = ["🍬", "🍫", "🍭", "🍡", "🍩", "🍪", "🍒"]; const treats = []; const radius = 15; const Cd = 0.47; // Dimensionless const rho = 1.22; // kg / m^3 const A = Math.PI * radius * radius / 10000; // m^2 const ag = 9.81; // m / s^2 const frameRate = 1 / 60; .........完整代码请登录后点击上方下载按钮下载查看
网友评论0