Html5 闪眼网页

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>闪眼</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      width: 100vw;
      height: 100vh;
      background-color: #27641b;
      text-align: center;
      padding-top: 200px;
    }

    .box h2 {
      font-size: 70px;
    }
  </style>
</head>

<body>
  <div class="box">
    <h2>闪眼系列1.0</h2>
    <button id="startButton">开始</button>
    <button id="stopButton">停止</button>
  </div>
  <script>
    function getRandomColor(flag) {
      // 如果是true,返回#ffffff
      if (flag) {
        let str = '#';
        let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
        for (let i = 1; i <= 6; i++) {
          let index = Math.floor(Math.random() * arr.length);
          str += arr[index];
        }
        return str;
      } else {
        // 否则返回rgb(255,255,255)
        let r = Math.floor(Math.random() * 256);
        let g = Math.floor(Math.random() * 256);
        let b = Math.floor(Math.random() * 256);
        return `rgba(${r},${g},${b})`;
      }
    }
    const boxElement = document.querySelector('.box');
    const h3 = document.querySelector('.box h2');
    let intervalId; // 用于存储定时器的标识符

    const myFunction = () => {
      let color = getRandomColor(true);
      boxElement.style.backgroundColor = color;
      let colorh3 = getRandomColor(false);
      h3.style.color = colorh3;
    };

    const startInterval = () => {
      let speedms = +prompt('请输入闪眼速度:(ms)/次');
      intervalId = setInterval(myFunction, speedms);
    };

    const stopInterval = () => {
      clearInterval(intervalId);
    };

    // 绑定按钮的点击事件
    const stopButton = document.querySelector('#stopButton');
    stopButton.addEventListener('click', () => {
      stopInterval();
    });
    // 绑定按钮的点击事件
    const startButton = document.querySelector('#startButton');
    startButton.addEventListener('click', () => {
      startInterval();
    });
    // 我的网页地址 http://brandon.3vcn.work

  </script>
</body>

</html>

”低级饱和,高级缺乏“

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值