当前位置:网站首页>按钮点击动画
按钮点击动画
2022-08-09 02:30:00 【JiuMeilove】
效果示例
代码示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>按钮点击动画1</title>
<style> @import url('https://fonts.googleapis.com/css2?family=Pacifico&display=swap'); html, body {
width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background-color: #1f1f1f; font-family: 'Pacifico', serif; overflow: hidden; } span {
position: relative; display: flex; align-items: center; justify-content: center; flex-grow: 1; } span::after {
content: attr(data-text); position: absolute; background-color: #FC4F4F; border-radius: 10px; padding: 6px 20px; font-size: 22px; cursor: pointer; color: #fff; user-select: none; transition: transform 100ms ease-in; } span:active::after {
transform: scale(0.9); } @keyframes pumping {
50% {
transform: scale(0.95); } } .shape {
--size: 8px; position: absolute; top: calc(50% - var(--size)); left: calc(50% - var(--size)); width: calc(var(--size) * 2); height: calc(var(--size) * 2); animation: popup var(--d) cubic-bezier(.08, .56, .53, .98) forwards; } .heart {
--size: 6px; background-color: var(--c); } .heart::before, .heart::after {
content: ""; position: absolute; width: 100%; height: 100%; background-color: var(--c); border-radius: 50%; } .heart::before {
left: -50%; } .heart::after {
top: -50%; } @keyframes popup {
0% {
opacity: 0; } 60% {
opacity: 1; } 100% {
opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--r)); } } </style>
</head>
<body>
<span data-text="Click Me"></span>
<script> const colors = ['#FC4F4F', '#FFBC80', '#FF9F45', '#F76E11'] // const shapes = ['square', 'circle', 'triangle', 'heart'] const shapes = ['heart'] const randomIntBetween = (min, max) => {
return Math.floor(Math.random() * (max - min + 1) + min) } class Particle {
constructor({
x, y, rotation, shape, color, size, duration, parent }) {
this.x = x this.y = y this.parent = parent this.rotation = rotation this.shape = shape this.color = color this.size = size this.duration = duration this.children = document.createElement('div') } draw() {
this.children.style.setProperty('--x', this.x + 'px') this.children.style.setProperty('--y', this.y + 'px') this.children.style.setProperty('--r', this.rotation + 'deg') this.children.style.setProperty('--c', this.color) this.children.style.setProperty('--size', this.size + 'px') this.children.style.setProperty('--d', this.duration + 'ms') this.children.className = `shape ${
this.shape}` this.parent.append(this.children) } animate() {
this.draw() const timer = setTimeout(() => {
this.parent.removeChild(this.children) clearTimeout(timer) }, this.duration) } } function animateParticles({
total }) {
for (let i = 0; i < total; i++) {
const particle = new Particle({
x: randomIntBetween(-200, 200), y: randomIntBetween(-100, -300), rotation: randomIntBetween(-360 * 5, 360 * 5), shape: shapes[randomIntBetween(0, shapes.length - 1)], color: colors[randomIntBetween(0, colors.length - 1)], size: randomIntBetween(4, 7), duration: randomIntBetween(400, 800), parent }) particle.animate() } } const parent = document.querySelector('span') parent.addEventListener("touchstart", () => {
}, false); parent.addEventListener('click', e => animateParticles({
total: 40 }) ) </script>
</body>
</html>
边栏推荐
- 物联网未来:未来五年的预期
- HMS Core分析服务智能运营6.5.1版本上线
- Programmer's Daily Life | Daily Fun
- uart_spi练习
- 显著性检验--学习笔记
- 工具类:base64格式的数据与本地文件的相互转换
- A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event
- 年金险的安全性怎么样啊?可靠吗?
- 力扣刷题记录1.5-----367. 有效的完全平方数
- 2022 Eye Health Brand Franchise Exhibition, Beijing Vision Care Exhibition, China Ophthalmology Technology Summit
猜你喜欢
随机推荐
Significance Test--Study Notes
显著性检验--学习笔记
My thoughts on software development
Likou Brush Question Record 8.1-----206. Reverse linked list
连接数据库且在网页运行的RDLC
2022年自然语言处理校招社招实习必备知识点盘点分享
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
数字 05 verilog&vivado2018.2零散笔记
C#计算两个时间相差多少天、时、分、秒
js实现数组去重的方式(7种)
【AspNetCore】实现JWT(使用Microsoft.AspNetCore.Authentication.JwtBearer)
Likou Brush Question Record 5.1-----59. Spiral Matrix II
高性能 MySQL(十二):分区表
2020.12.4 log
Summary of Database Design
全志平台双路LVDS配置
Redis系列文章导航
Maya engine modeling
危化企业双预防机制数字化建设工作要求
SQLite切换日志模式优化