喜欢收藏按钮点击动画特效
代码语言:html
所属分类:表单美化
代码描述:喜欢收藏按钮点击动画特效
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> * { box-sizing: border-box; } body { min-height: 100vh; display: -webkit-box; display: flex; -webkit-box-align: center; align-items: center; -webkit-box-pack: center; justify-content: center; background: #fafafa; } body > * + * { margin-right: 24px; } :root { --transition: 0.3; --heart-fill: #e63b19; } .heart { height: 100%; width: 100%; position: absolute; } .heart--stroke { stroke: var(--heart-stroke); stroke-width: 2.5px; fill: none; } .heart--fill { stroke: none; fill: var(--heart-fill); -webkit-transform: scale(var(--scale, 0)); transform: scale(var(--scale, 0)); } .heart__particle { height: 16px; width: 16px; position: absolute; top: 50%; left: 50%; border-radius: 50%; background: hsl(var(--h), 80%, 70%); -webkit-transform: translate(-50%, -50%) rotate(calc(var(--r, 0) * 1deg)) translate(0, calc(var(--radius, 0) * 1px)) scale(0); transform: translate(-50%, -50%) rotate(calc(var(--r, 0) * 1deg)) translate(0, calc(var(--radius, 0) * 1px)) scale(0); } .button { height: 40px; border: 0; cursor: pointer; border-radius: 6px; position: relative; display: -webkit-box; display: flex; -webkit-box-align: center; align-items: center; -webkit-box-pack: center; justify-content: center; width: 100px; font-family: sans-serif; text-align: left; outline: transparent; color: var(--stroke); background: var(--fill); background: hsl(var(--hue), calc(var(--saturation) * 1%), calc(var(--lightness) * 1%)); box-shadow: 2px 4px 4px rgba(26,26,26,0.5); -webkit-transition: box-shadow 0.2s, background 0.2s; transition: box-shadow 0.2s, background 0.2s; } .button--primary { --hue: 260; --saturation: 50; --lightness: 20; --stroke: #fff; --heart-stroke: #fff; margin-right: 24px; } .button--secondary { --hue: 0; --saturation: 0; --lightness: 100; --stroke: #666; --heart-stroke: #999; } .button__text { margin-right: 6px; opacity: var(--opacity); } .button__icon { position: relative; height: 24px; width: 24px; } .button:hover { --scale: 0.3; background: hsl(var(--hue), calc(var(--saturation) * 1%), calc(var(--lightness) * 0.96%)); box-shadow: 2px 2px 4px rgba(26,26,26,0.5); } .button:hover .heart--fill { -webkit-transition: -webkit-transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5); transition: -webkit-transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5); transition: transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5); transition: transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5), -webkit-transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5); } .button:active { background: hsl(var(--hue), calc(var(--saturation) * 1%), calc(var(--lightness) * 0.92%)); box-shadow: 0 0 0 rgba(26,26,26,0.5); } .button--active, .button--active:hover { --scale: 0.94; --opacity: 0.25; } .button--active .heart--fill, .button--active:hover .heart--fill { -webkit-transition: -webkit-transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5); transition: -webkit-transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5); transition: transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5); transition: transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5), -webkit-transform calc(var(--transition) * 1s) cubic-bezier(0.7, 0.9, 0.6, 2.5); } .button--active .button__text, .button--active:hover .button__text { -webkit-transition: opacity 0.1s; transition: opacity 0.1s; } .button--active .heart__particle, .button--active:hover .heart__particle { opacity: 0; -webkit-transform: translate(-50%, -50%) rotate(calc(var(--r, 0) * 1deg)) translate(0, calc(var(--d, 0) * 1px)) scale(var(--s)); transform: translate(-50%, -50%) rotate(calc(var(--r, 0) * 1deg)) translate(0, calc(var(--d, 0) * 1px)) scale(var(--s)); -webkit-transition: opacity calc(var(--transition) * 0.25s) calc(var(--t) * 1.25s), -webkit-transform calc(var(--t) * 1.25s) calc(var(--transition) * 0.5s); transition: opacity calc(var(--transition) * 0.25s) calc(var(--t) * 1.25s), -webkit-transform calc(var(--t) * 1.25s) calc(var(--transition) * 0.5s); transition: transform calc(var(--t) * 1.25s) calc(var(--transition) * 0.5s), opacity calc(var(--transition) * 0.25s) calc(var(--t) * 1.25s); transition: transform calc(var(--t) * 1.25s) calc(var(--transition) * 0.5s), opacity calc(var(--transition) * 0.25s) calc(var(--t) * 1.25s), -webkit-transform calc(var(--t) * 1.25s) calc(var(--transition) * 0.5s); } </style> </head> <body translate="no"> <button class="button button--primary"><span class="button__text">Love</span><span class="button__icon"><span class="heart__particles"><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle"></span><span class="heart__particle">.........完整代码请登录后点击上方下载按钮下载查看
网友评论0