HLJ 发布于
2024-04-27 23:08:28

css3 rotate旋转动画 暂停后还保持角度

//此处粘贴代码
<!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 type="text/css">
        .music-play {
            animation: rightWhirl 5s linear infinite;
            animation-play-state: running;
            /* 默认运行动画 */
            animation-fill-mode: forwards;
            /* 在运动结束时保留最后的状态 */
        }

        .music-paused {
            animation-play-state: paused;
        }

        @keyframes rightWhirl {
            0% {
                -webkit-transform: rotate(0)
            }

            100% {
                -webkit-transform: rotate(360deg)
            }
        }
    </style>

</head>

<body>
    <img id="image" src="http://good1230.com/dist/server/images/user/1613695591.jpg" class="music-play">
    <button id="paused">暂停</button>
    <button id="play">继续</button>
</body>
<script type="text/javascript">
    const img = document.getElementById('image')
    const play = document.getElementById('play')
    const paused = document.getElementById('paused')
    if (img) {
        play.onclick = function () {
            img.className = 'music-play'
        }
        paused.onclick = function () {
            img.className = 'music-play music-paused'
        }
    }

</script>

</html>
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2024-04-27/635.html
最后生成于 2024-04-27 23:08:28
此内容有帮助 ?
0