测试文章

2021-12-28 61℃

<!DOCTYPE html>

<html lang="zh-CN">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>随机变色小魔盒</title>

  <style>

    body {

      margin: 0;

      height: 100vh;

      display: flex;

      justify-content: center;

      align-items: center;

      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

      transition: background-color 0.5s ease;

      background-color: #f0f0f0;

    }

    .card {

      background: rgba(255, 255, 255, 0.85);

      backdrop-filter: blur(10px);

      border-radius: 20px;

      padding: 2rem 3rem;

      box-shadow: 0 10px 30px rgba(0,0,0,0.1);

      text-align: center;

    }

    h1 {

      margin-bottom: 1rem;

      color: #333;

    }

    button {

      background: #4a90e2;

      border: none;

      color: white;

      padding: 0.8rem 2rem;

      font-size: 1.2rem;

      border-radius: 50px;

      cursor: pointer;

      transition: transform 0.2s, background 0.3s;

      box-shadow: 0 4px 15px rgba(74,144,226,0.4);

    }

    button:hover {

      transform: scale(1.05);

      background: #357abd;

    }

    button:active {

      transform: scale(0.98);

    }

    #color-code {

      margin-top: 1.2rem;

      font-size: 1.1rem;

      color: #555;

      font-weight: bold;

    }

  </style>

</head>

<body>

  <div class="card">

    <h1>🎨 点一下,换个心情色</h1>

    <button id="changeBtn">换颜色</button>

    <p id="color-code">当前颜色:#f0f0f0</p>

  </div>

 

  <script>

    const btn = document.getElementById('changeBtn');

    const colorCode = document.getElementById('color-code');

    const body = document.body;

 

    function getRandomColor() {

      const letters = '0123456789ABCDEF';

      let color = '#';

      for (let i = 0; i < 6; i++) {

        color += letters[Math.floor(Math.random() * 16)];

      }

      return color;

    }

 

    btn.addEventListener('click', () => {

      const newColor = getRandomColor();

      body.style.backgroundColor = newColor;

      colorCode.textContent = `当前颜色:${newColor}`;

    });

  </script>

</body>

</html>

标签: 测试

非特殊说明,本博所有文章均为博主原创。