css波浪音阶,过渡动画案例

本文详细介绍了如何使用CSS3创建过渡动画效果,通过scale变换实现元素的高度伸展动画,同时结合关键帧动画实现颜色变化,展示了动画的延迟和无限循环播放特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

css3过渡动画

<style>
        .box{
            width: 225px;
            height: 200px;
            margin: 50px auto;/*元素在父元素里面水平居中*/
        }
        .item{
            float: left;/*让元素从左到右在一行排列*/
            width: 10px;
            height: 100px;
            background-color: #999;
            border-radius: 5px;
            margin:0 2.5px;
            transform: scale(1,0.2);
            /*
            外边距
                margin:5px 10px;   上下   左右
                margin-top
                margin-bottom
                margin-left
                margin-right

            */
        }
        .first{
            animation: scale 2s linear infinite alternate;
        }
        .second{
            animation: scale 2s 0.3s linear infinite alternate;
        }
        .third{
            animation: scale 2s 0.6s linear infinite alternate;
        }
        .fourth{
            animation: scale 2s 0.9s linear infinite alternate;
        }
        .fifth{
            animation: scale 2s 1.2s linear infinite alternate;
        }
        .sixth{
            animation: scale 2s 1.5s linear infinite alternate;
        }
        .seventh{
            animation: scale 2s 1.8s linear infinite alternate;
        }
        .eighth{
            animation: scale 2s 2.1s linear infinite alternate;
        }

        @keyframes scale {
            0%{
                transform: scale(1,0.2);
                background-color: #999;
            }
            100%{
                transform: scale(1,1);
                background-color: #333;
            }
        }
    </style>
<body>
    <div class="box">
        <div class="item eighth"></div>
        <div class="item seventh"></div>
        <div class="item sixth"></div>
        <div class="item fifth"></div>
        <div class="item fourth"></div>
        <div class="item third"></div>
        <div class="item second"></div>
        <div class="item first"></div>
        <div class="item second"></div>
        <div class="item third"></div>
        <div class="item fourth"></div>
        <div class="item fifth"></div>
        <div class="item sixth"></div>
        <div class="item seventh"></div>
        <div class="item eighth"></div>
    </div>
</body>

效果图
在这里插入图片描述

js代码 [removed] var wave = (function () { var ctx; var waveImage; var canvasWidth; var canvasHeight; var needAnimate = false; function init (callback) { var wave = document.getElementById('wave'); var canvas = document.createElement('canvas'); if (!canvas.getContext) return; ctx = canvas.getContext('2d'); canvasWidth = wave.offsetWidth; canvasHeight = wave.offsetHeight; canvas.setAttribute('width', canvasWidth); canvas.setAttribute('height', canvasHeight); wave.appendChild(canvas); waveImage = new Image(); waveImage.onload = function () { waveImage.onload = null; callback(); } waveImage.src = 'images/wave.png'; } function animate () { var waveX = 0; var waveY = 0; var waveX_min = -203; var waveY_max = canvasHeight * 0.7; var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000 / 60); }; function loop () { ctx.clearRect(0, 0, canvasWidth, canvasHeight); if (!needAnimate) return; if (waveY < waveY_max) waveY = 1.5; if (waveX < waveX_min) waveX = 0; else waveX -= 3; ctx.globalCompositeOperation = 'source-over'; ctx.beginPath(); ctx.arc(canvasWidth/2, canvasHeight/2, canvasHeight/2, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); ctx.globalCompositeOperation = 'source-in'; ctx.drawImage(waveImage, waveX, canvasHeight - waveY); requestAnimationFrame(loop); } loop(); } function start () { if (!ctx) return init(start); needAnimate = true; setTimeout(function () { if (needAnimate) animate(); }, 500); } function stop () { needAnimate = false; } return {start: start, stop: stop}; }()); wave.start(); [removed]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值