跑马灯边框、动态边框的实现

代码如下:

<!DOCTYPE html>
    <html>
    <head>
        <!-- 声明当前页面的编码集: chartset=gbk,gb2312(中文编码), utf-8(国际编码) -->
        <meta charset="UTF-8">
        <!-- 当前页面三要素 -->
        <title>动态边框</title>
        <meta name="keywords" >
        <meta name="description">
        <style>
            /* 重置浏览器默认样式 start */
            * { margin: 0; padding: 0; }
            body {
              background: #212534;
              margin: 0;
              padding: 0;
              height: 100vh;
              display: flex;
              align-items: center;
              justify-content: center;
              flex-direction: column;
            }
            a { text-decoration: none; }
            ul li { list-style: none; }
            /* 重置浏览器默认样 end */
            .spin {
              overflow: hidden;
              position: relative;
              width: 300px;
              height: 300px;
              display: flex;
              justify-content: center;
              align-items: center;
            }
            .spin-circle {
              position: absolute;
              width: 500px;
              height: 500px;
              border-radius: 50%;
              background: linear-gradient(#e1ff5d, #209471, #2c0270, #910472) ;
              z-index: -1;
              animation: spin 2s linear infinite;
            }
            .pause {
              animation-play-state: paused;
            }
            .content {
              width: 280px;
              height: 280px;
              background: linear-gradient(#d9c9e0, #b0a3b6, #97879e, #8543a3);
            }
            @keyframes spin {
              0% {
                transform: rotate(0);
              }
              100% {
                transform: rotate(360deg);
              }
            }
            button {
              margin-top: 20px;
              width: 150px;
              height: 50px;
              font-size: 20px;
              border-radius: 10px;
            }
        </style>
    </head>
    <body>
      <div class="spin">
        <div class="spin-circle"></div>
        <div class="content"></div>
      </div>
      <button onclick="onPause()">暂停/播放</button>
    </body>
</html>
<script>
  function onPause() {
    let el = document.querySelector('.spin-circle');
    if (el.classList.contains('pause')) {
      el.classList.remove('pause');
    } else {
      el.classList.add('pause');
    }
  }
</script>

效果如图:

可以暂停和播放动画效果哦!!!
在这里插入图片描述
ps:如果想看最终的效果,请点击下载!动态边框

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值