首页首页
前端
非前端
辅助
Github
前端
非前端
辅助
Github
  • 前端基础

    • HTML基础
    • CSS基础
    • JS基础
    • ES6基础
    • HTTP基础
    • 前端缓存
    • 页面性能
    • 数据结构基础
    • 我的文章
  • 前端进阶

    • Vue2基础
    • Vue2进阶
    • Vue3基础
    • Vue3进阶
    • React基础
    • React进阶
    • React18新特性
    • Vue和React对比
    • RN基础
    • RN环境搭建和打包发布
    • 打包工具
    • TS基础
    • Nuxt基础
    • 小程序基础
    • 微前端基础
    • uni-app基础
    • 业务相关
    • 低代码相关
  • 前端代码练习

    • CSS代码练习
    • JS代码练习
    • 算法代码练习
  • 前端代码技巧

    • 工具库
    • 工具函数
    • CSS动画库
    • CSS代码技巧
    • JS代码技巧
    • 项目技巧

1、点击按钮缩放动画

.activeBtn {
    &:active {
        animation: animateBtn 0.4s;
    }
}
@keyframes animateBtn {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.86);
    }
    100% {
        transform: scale(1);
    }
}

2、上下浮动动画

animation: upDown 2s infinite;

@keyframes upDown {
    0% {
        transform: translate(0px, 0px);
    }
    50% {
        transform: translate(0px, -30px);
    }
    100% {
        transform: translate(0px, 0px);
    }
}

3、左右晃动小动画

<span class="red-packets"></span>

.red-packets {
    display: inline-block;
    width: 35px;
    height: 40px;
    background: url('https://iknowpc.bdimg.com/static/question-new/widget/ask/replyer/img/wld-exp-btn-hb.f91c70d.png')
        no-repeat;
    background-size: 100% 100%;
    animation-name: upAnimation;
    transform-origin: center bottom;
    animation-duration: 2s;
    animation-fill-mode: both;
    animation-iteration-count: infinite;
    animation-delay: 0.5s;
}
@keyframes upAnimation {
    0% {
        transform: rotate(0deg);
        transition-timing-function: cubic-bezier(
            0.215,
            0.61,
            0.355,
            1
        );
    }
    10% {
        transform: rotate(-12deg);
        transition-timing-function: cubic-bezier(
            0.215,
            0.61,
            0.355,
            1
        );
    }
    20% {
        transform: rotate(12deg);
        transition-timing-function: cubic-bezier(
            0.215,
            0.61,
            0.355,
            1
        );
    }
    28% {
        transform: rotate(-10deg);
        transition-timing-function: cubic-bezier(
            0.215,
            0.61,
            0.355,
            1
        );
    }
    36% {
        transform: rotate(10deg);
        transition-timing-function: cubic-bezier(
            0.755,
            0.5,
            0.855,
            0.06
        );
    }
    42% {
        transform: rotate(-8deg);
        transition-timing-function: cubic-bezier(
            0.755,
            0.5,
            0.855,
            0.06
        );
    }
    48% {
        transform: rotate(8deg);
        transition-timing-function: cubic-bezier(
            0.755,
            0.5,
            0.855,
            0.06
        );
    }
    52% {
        transform: rotate(-4deg);
        transition-timing-function: cubic-bezier(
            0.755,
            0.5,
            0.855,
            0.06
        );
    }
    56% {
        transform: rotate(4deg);
        transition-timing-function: cubic-bezier(
            0.755,
            0.5,
            0.855,
            0.06
        );
    }
    60% {
        transform: rotate(0deg);
        transition-timing-function: cubic-bezier(
            0.755,
            0.5,
            0.855,
            0.06
        );
    }
    100% {
        transform: rotate(0deg);
        transition-timing-function: cubic-bezier(
            0.215,
            0.61,
            0.355,
            1
        );
    }
}

4、水波纹动画

<div class="circle-breath"></div>
.circle-breath {
    background: pink;
    height: 36px;
    width: 36px;
    border-radius: 50%;
    animation: donghua 2.4s infinite;
}

@keyframes donghua {
    0% {
        transform: scale(0.60);
        /* 注意rgba中的a的设置 */
        box-shadow: 0 0 0 0 rgba(204, 73, 152, 60%);
    }

    60% {
        transform: scale(1);
        box-shadow: 0 0 0 36px rgba(204, 73, 152, 0%);
    }

    100% {
        transform: scale(0.60);
        box-shadow: 0 0 0 0 rgba(204, 73, 152, 0%);
    }
}

5、语音声纹动画

<button class="microphone-btn">
    <div class="microphone-icon recording">
        <div class="wave"></div>
        <div class="wave"></div>
        <div class="wave"></div>
    </div>
</button>
.microphone-btn {
    border: none;
    background-color: transparent;
    cursor: pointer;
    position: relative;
    outline: none;
}

.microphone-icon {
    width: 50px;
    height: 50px;
    background-color: #333;
    border-radius: 50%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.3s;
}

.microphone-icon::before {
    content: '';
    width: 20px;
    height: 30px;
    background-color: #fff;
    border-radius: 10px 10px 0 0;
    position: absolute;
    top: 5px;
}

.microphone-icon::after {
    content: '';
    width: 10px;
    height: 10px;
    background-color: #fff;
    border-radius: 50%;
    position: absolute;
    bottom: 5px;
}

.wave {
    position: absolute;
    border: 4px solid #f00; /* 设置线的粗细 */
    border-radius: 50%;
    opacity: 0;
    animation: wave-animation 1.5s infinite;
}

.microphone-icon.recording .wave:nth-child(1) {
    animation-delay: 0s;
}

.microphone-icon.recording .wave:nth-child(2) {
    animation-delay: 0.5s;
}

.microphone-icon.recording .wave:nth-child(3) {
    animation-delay: 1s;
}

@keyframes wave-animation {
    0% {
        width: 50px;
        height: 50px;
        opacity: 1;
        border-color: rgba(255, 0, 0, 1);
    }
    100% {
        width: 150px;
        height: 150px;
        opacity: 0;
        border-color: rgba(255, 0, 0, 0);
    }
}
最后更新: 2024/11/23 14:02
Prev
工具函数
Next
CSS代码技巧