模拟音乐播放时图片旋转效果(css3)

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 300px;
            height: 300px;
            border-radius: 50%;
            background: url("./images/04.jpg");
            background-size: cover;
            /* 执行run动画 无限循环 默认暂停*/
            animation: run 10s linear infinite paused;
        }
        /* 自定义动画 */
        @keyframes run{
            from{
                /* 旋转效果 */
                transform: rotateZ(0);
            }
            to{
                transform: rotateZ(720deg);
            }
        }
    </style>
</head>
<body>
    <div id="box"></div>
    <!-- 音乐 默认不显示 -->
    <audio id="mv" src="./creep.mp3"></audio>
</body>
</html>
<script>
    box.onclick=function(){
        // 获取当前盒子的动画播放状态
        let status = box.style.animationPlayState
        console.log(status)
        if(status==''|| status==='paused'){//暂停状态
            // 运行动画
            box.style.animationPlayState = 'running'
            // 播放音乐
            mv.play()
        }else{
            // 暂停音乐和动画
            box.style.animationPlayState = 'paused'
            mv.pause()
        }
    }
</script>
  • 9
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值